首页 > 解决方案 > 滚动视图上的文本输入值

问题描述

我想改变 textInput 的值,但它改变了 textinput 的所有值,我知道是因为状态,但是处理这个 textInput 的正确方法或我使用的是来自 react-native-numeric-input 的 numericInput,感谢您的帮助。

<ScrollView>
  {this.state.display.map((info)=>{
    return 
    <View style={{paddingBottom:5,alignSelf:'center'}} key={info.id}>
      <View style={{ ... }}>
        <View style={{flexDirection:'row'}}>
          ...
          <View style={{justifyContent:'center',marginLeft:'auto',marginRight:10}}>
            <NumericInput 
              totalWidth={70} 
              totalHeight={30} 
              iconSize={10}
              initValue={this.state.v6}
              value={this.state.v6}
              onChange={(v6) => this.setState({ v6 })} 
              rounded 
              textColor='#59656F' 
              iconStyle={{ color: 'white' }} 
              rightButtonBackgroundColor='#AC9FBB' 
              leftButtonBackgroundColor='#DDBDD5' 
            />
          </View>
        </View>
      </View>
    </View> 
  })}
</ScrollView>

这是我的州代码

state={
  v6:0
}

标签: react-nativeexporeact-native-textinput

解决方案


尝试将 onChange 更改为:

onChange={(value) => this.setState({ v6: value })} 

推荐阅读