无法在 React Native 中编辑 TextInput 数据
Unable to edit TextInput data in react native
我是 React Native 的新手。我正在尝试更新 TextInput 字段中的数据,但它不允许我对其进行编辑。这是我正在使用的代码。
<TextInput style = {styles.textInputStyle}
underlineColorAndroid = "transparent"
placeholder = "Student First Name"
placeholderTextColor = "gray"
autoCapitalize = "none"
onChangeText = {this.handleFirstName}
value={this.props.navigation.state.params.firstName}
/>
handleFirstName = (text) => {
this.setState({ firstName: text })
}
同样的代码在 IOS 设备中工作,因为它不允许编辑 Android 中的值。
如果您需要更多详细信息,请告诉我。
提前致谢。
您必须将初始值(从 props 获得)设置为构造函数中的状态,然后在 value
中引用状态
<TextInput style = {styles.textInputStyle}
underlineColorAndroid = "transparent"
placeholder = "Student First Name"
placeholderTextColor = "gray"
autoCapitalize = "none"
onChangeText = {this.handleFirstName}
value={this.state.firstName}
/>
在构造函数中如下
constructor(props){
....
this.state = { firstName: props.navigation.state.params.firstName }
....
}
这篇link
中提到了
我是 React Native 的新手。我正在尝试更新 TextInput 字段中的数据,但它不允许我对其进行编辑。这是我正在使用的代码。
<TextInput style = {styles.textInputStyle}
underlineColorAndroid = "transparent"
placeholder = "Student First Name"
placeholderTextColor = "gray"
autoCapitalize = "none"
onChangeText = {this.handleFirstName}
value={this.props.navigation.state.params.firstName}
/>
handleFirstName = (text) => {
this.setState({ firstName: text })
}
同样的代码在 IOS 设备中工作,因为它不允许编辑 Android 中的值。
如果您需要更多详细信息,请告诉我。 提前致谢。
您必须将初始值(从 props 获得)设置为构造函数中的状态,然后在 value
<TextInput style = {styles.textInputStyle}
underlineColorAndroid = "transparent"
placeholder = "Student First Name"
placeholderTextColor = "gray"
autoCapitalize = "none"
onChangeText = {this.handleFirstName}
value={this.state.firstName}
/>
在构造函数中如下
constructor(props){
....
this.state = { firstName: props.navigation.state.params.firstName }
....
}
这篇link
中提到了