gpt4 book ai didi

android - 无法在 React Native 中编辑 TextInput 数据

转载 作者:行者123 更新时间:2023-11-29 01:01:28 25 4
gpt4 key购买 nike

我是 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 中提到了它

关于android - 无法在 React Native 中编辑 TextInput 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50849738/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com