添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account 比如有下拉框的选项:[1,2,3,4,5],另外我还有5个按钮,分别是1-5.
我在1-5按钮的事件中,把对应的数字写入state,
然后把这个state赋予下拉框的defaultValue。
发现:如果app启动后,没有通过下拉框选择前,按钮的值可以设置到下拉框上;
如果一旦下拉框手工改变了选择值,那么之后再按钮的值就设置不上去了。
测试代码如下:
class test extends Component {
constructor(props) {
super(props);
this.state = {seleted : '2',
render() {
return (

    <View style={{height:40,flexDirection: 'row',justifyContent: 'space-between' }}>
		<Button title={'1'} onPress={() => this.setState({seleted: '1'})} />
		<Button title={'2'} onPress={() => this.setState({seleted: '2'})} />
		<Button title={'3'} onPress={() => this.setState({seleted: '3'})} />
		<Button title={'4'} onPress={() => this.setState({seleted: '4'})} />
		<Button title={'5'} onPress={() => this.setState({seleted: '5'})} />
		<ModalDropdown options={['1','2','3','4','5']}
				defaultValue={this.state.seleted}
				onSelect={(idx, value) => this.setState({seleted: value})} />
    </View>
只能循环options拿到对应的Idx?

我的建议是options的列表(如果是一组对象)由您来维护,将这组对象map成string的数组作为options传给控件,这样您可以更方便的对对象列表进行查询等操作,您认为呢?

另外:能否让option的显示的是描述,而实际拿到的是value呢,就像html中的下拉框那样

onSelect方法中可以得到value和idx两个值,不知道是否满足您的需求。