我的代码从“ react-native-material-dropdown”中有两个下拉列表。当在第一个下拉列表中选择一个元素时,第一个填充在开头,第二个填充(从获取json数据开始)。
这是我到目前为止所写的:
... import { Dropdown } from 'react-native-material-dropdown'; export default class Example extends Component { render() { let firstValues = [{ value: 'AAA', }, { value: 'BBB', }, { value: 'CCC', }]; return ( <View> <Dropdown label='First' data={firstValues} onChangeText={(value)=>{ fetch("...") .then(response => response.json()) .then((responseJson)=> { var count = Object.keys(responseJson.myJson).length; let secondValues = []; for(var i=0;i<count;i++){ secondValues.push({ value: responseJson.myJson[i].name }); } this.setState({ secondValues }); }) .catch((error) => { alert('Error'); }); }} /> <Dropdown label='Second' data={this.secondValues} /> </View> ) } } ...
问题在于第二个下拉列表从不更新,并且始终为空。我仍然是初学者,所以我们将不胜感激。谢谢。
我的代码从“ react-native-material-dropdown”中有两个下拉列表。当元素为...
在第二个DropDown中,您没有正确获得状态值