我需要更改_dropdown_select()
我的代码中另一个事件的方法发生。我正在使用sohobloo/react-native-modal-dropdown在我的 react native 应用程序中。
我尝试将此作为我的 <ModalDropdown>
上的属性标签:
select={(idx)=> this._dropdown_select(idx).bind(this)}
我的方法:
_dropdown_select(idx){
return idx;
}
我这样调用它:
this._dropdown_select(0);
在另一个方法中
最佳答案
在属性中:
<ModalDropdown options={['option 1', 'option 2']}
onSelect={this._dropdown_select}
defaultIndex={this.state.selectedIndex}
>
...
</ModalDropdown>
构造函数
constructor(props) {
super(props)
this.state = {selectedIndex: '', dropDown:{}}
this._dropdown_select = this._dropdown_select.bind(this)
}
方法:
_dropdown_select(event){
this.setState({selectedIndex: event.target.index, dropDown:event})
}
调用选择方法
this.state.dropDown.select(2)
关于javascript - react-native-modal-dropdown 无法以编程方式更改所选内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45906711/