Reactjs 在另一个下拉列表上选择值时更新下拉列表

Reactjs 在另一个下拉列表上选择值时更新下拉列表,reactjs,react-native,cascadingdropdown,Reactjs,React Native,Cascadingdropdown,我的代码有两个“react native material dropdown”的下拉列表。第一个在开始时填充,第二个必须在第一个下拉列表中选择元素时填充(从获取json数据) 到目前为止,我只写了以下内容: ... import { Dropdown } from 'react-native-material-dropdown'; export default class Example extends Component { render() { let firstValues

我的代码有两个“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};
导出默认类示例扩展组件{
render(){
设第一个值=[{
值:“AAA”,
}, {
值:“BBB”,
}, {
值:“CCC”,
}];
返回(
{
取回(“…”)
.then(response=>response.json())
.然后((responseJson)=>{
var count=Object.keys(responseJson.myJson).length;
设secondValues=[];
对于(var i=0;i{
警报(“错误”);
});
}}
/>
)
}
}
...

问题是,第二个下拉列表从不更新,而且总是空的。
我还是一个初学者,所以任何帮助都将不胜感激。


谢谢。

在第二个下拉列表中,您没有正确获取状态值

更改此设置

<Dropdown
  label='Second'
  data={this.secondValues}
/>

<Dropdown
  label='Second'
  data={this.state.secondValues}
/>