【问题标题】:React Native - Connect two pickersReact Native - 连接两个选择器
【发布时间】:2019-01-31 22:34:46
【问题描述】:

如何在 react native 中连接两个选择器。

例如,用户有 first_name 和 last_name。当用户单击第一个选择器并选择 first_name 时,会自动更改第二个选择器 last_name 中的值。

例如,我们有 first_name = 'John' 和 last_name = 'Deep' 的用户。当用户点击第一个选择器 John 时,自动在第二个选择器中将值设置为 Deep。

我不使用库作为选择器,但我使用库作为本地数据库:https://www.npmjs.com/package/react-native-sqlite-storage

【问题讨论】:

    标签: javascript database sqlite react-native picker


    【解决方案1】:

    每次选择器更改时,您都可以使用onValueChange 调用函数

    <Picker
       selectedValue={this.state.firsname}
       style={{height: 50, width: 100}}
       onValueChange={(itemValue, itemIndex) =>
        this.yourfunc(itemValue, itemIndex)
       }>
     <Picker.Item label="John" value="John" />
     <Picker.Item label="abc" value="abc" />
    </Picker>
    
    <Picker
       selectedValue={this.state.lastname}
       style={{height: 50, width: 100}}>
     <Picker.Item label="Deep" value="Deep" />
    </Picker>
    
    //set your selectedValue to the state where you save the value
    
    ....
    
    yourfunc = (val, index) => {
       //doing some stuff to change another picker
       let lastname = //get lastname from val
       //and then this.setState lastname
    }
    

    官方docs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-09
      • 2017-01-28
      相关资源
      最近更新 更多