我正在使用react本机选择器创建我的下拉列表,当我从dropddown1中选择1项时,我希望从dropdown2更新项目。谢谢。
发布于 2017-05-15 11:15:00
在react中,要更改UI,需要更新状态。通过查看react-native-chooser的文档,它有一个名为onSelect的回调方法。在这里,当前选定的选项将返回给您使用。根据所选选项,您可以更新第二个下拉列表的状态。这里的重要部分是父母和孩子的关系。在react中,只有在更新父状态(除非另有规定)时,才会重新呈现子级。一些伪码:
// Your method callback
onSelect = (option) => {
const newOptions = computeNewOptions(option)
this.setState({options: newOptions})
}
// Your Second dropdown component would take these options in as a prop
render () {
return (
<SecondDropDown options={this.state.options} />
)
}
// You can then access your options through the props
export default class SecondDropDown extends React.Component {
render () {
let myOptions = renderOptions(this.props.options)
return (
<View>
{myOptions}
</View>
)
}
}https://stackoverflow.com/questions/43977275
复制相似问题