反应本机文本输入插入和更新

时间:2018-05-19 04:44:52

标签: react-native react-native-android

我有一个有文字输入的屏幕。我试图将TextInput值插入数据库并从数据库中检索数据并显示在TextInput上没有任何问题。但问题是编辑TextInput上的数据。我尝试编辑TextInput值,无法更改文本。

if (this.state.mode == 'edit') {
    customer.updateCustomer(JSON.stringify(customerregVOObj)); 
} else {
    customerregVOObj._id = 'abc';
    customer.createCustomer(customerregVOObj); 
} 
updateCustomer = () => {
    customerregVOObj.shopName = this.state.shopName; 
}

<TextInput 
  underlineColorAndroid='transparent' style={styles.input}
  returnKeyType={"next"} autoFocus={true} placeholder="Shop Name"
  onChangeText={(text) => this.setState({ shopName: text })}
  value={this.state.shopDetail.shopName} 
/>



this.state.mode == 'new' ? <Button onPress={this.updateCustomer} title="Submit" /> :
  <Button onPress={this.updateCustomer} title="Update" />

1 个答案:

答案 0 :(得分:0)

您在中传递了错误的状态。请更换以下代码:

<TextInput 
  underlineColorAndroid='transparent' style={styles.input}
  returnKeyType={"next"} autoFocus={true} placeholder="Shop Name"
  onChangeText={(text) => this.setState({ shopName: text })}
  value={this.state.shopName} 
/>