【发布时间】:2020-02-13 08:11:48
【问题描述】:
我正在尝试在 react native 中连接两个下拉列表, 与国家和城市相同 如果我选择任何国家,它应该将该国家的城市加载到第二个下拉列表中 所有数据都在外部 json 文件中 但两个下拉菜单中都没有加载(选择器)
json 文件:
{
"interest": [
{
"RAW_MATERIAL":["abc","cde"]
},
{
"OEM_PARTS":["xyz","qwer"]
},
{
"CONSUMABLES":["poiu","fjgl"]
},
{
"SERVICE":["xvcbv","qweiw"]
}
],
}
我使用的反应原生选择器:
import React, { Component } from 'react';
import { Container,Picker,Button } from 'native-base';
const cData = require('../data.json');
export default class Vendorsupplies extends Component {
constructor(props) {
super(props);
this.state = {
interest:'',
interest2:''
};
}
interest(value: string) {
this.setState({
interest: value
});
}
interest2(value: string) {
this.setState({
interest2: value
});
}
<Picker
note
mode="dropdown"
style={{ width: 120 }}
selectedValue={this.state.interest}
onValueChange={this.interest.bind(this)}
name="intre"
>
{cData.interest.map((number) =>
<Picker.Item label={number.interest_in} value={number.interest_in} />
)}
</Picker>
<Picker
note
mode="dropdown"
style={{ width: 120 }}
selectedValue={this.state.intre2.interest}
onValueChange={this.intre2.interest.bind(this)}
name="intre2"
>
{cData.interest.map((number) =>
<Picker.Item label={number.intre2.interest_in} value={number.intre2.interest_in} />
)}
</Picker>
【问题讨论】:
-
你遇到了什么问题?
-
它不工作
-
“它不工作”是什么意思?为什么使用
intre2?不应该是this.interest.bind(this)和this.state.interest吗?
标签: json reactjs react-native react-native-android dropdown