我有一个有文字输入的屏幕。我试图将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" />
答案 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}
/>