简体   繁体   English

ReactNative 选择器值在选择时重置

[英]ReactNative picker value resets on selection

I am working on a react native component where it has a listview with different listitems.我正在开发一个 React Native 组件,它有一个包含不同列表项的列表视图。 ListItems have button on click of which it should show a reactnative pickerview . ListItems 有按钮,点击它应该显示一个 reactnative pickerview 。 Now everything works fine except the picker resets its value when i try to select anything from picker.现在一切正常,除了当我尝试从选择器中选择任何东西时选择器重置其值。

Not sure if its is because of Listview,renderRow or soemthing else .不确定是因为 Listview、renderRow 还是其他原因。

Any help will be much appreciated .任何帮助都感激不尽 。 Thanks谢谢

Code Snippet:-代码片段:-

render() {
    console.log('*** Rendeer called ***');
    return (
        <View style={styles.containerFullScreen}>
          <ListView dataSource={this.state.dataSource}
            renderRow={this.renderRow}
            renderSectionHeader={this.renderSectionHeader}>
          </ListView>

        <Picker
         mode="dropdown">
          <Picker.Item label="Java" value="java" />
          <Picker.Item label="JavaScript" value="js" />
          <Picker.Item label="Swift" value="swift" />
        </Picker>


          <TouchableHighlight
            activeOpacity={0.6}
            underlayColor={'transparent'}
            style = {styles.continueBtn}
            onPress={() => this.continueBtnAction()}>
            <Text style={styles.continueBtnText}>CONTINUE</Text>
         </TouchableHighlight>
        </View>
    );

You need to listen to onValueChange and pass the selectedValue props.您需要监听onValueChange并传递selectedValue道具。

Check the Picker documentationhttps://facebook.github.io/react-native/docs/picker.html#picker检查 Picker 文档https://facebook.github.io/react-native/docs/picker.html#picker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM