【发布时间】:2017-04-23 13:19:22
【问题描述】:
我正在使用 react-native-maps 制作一个应用程序,现在我正在添加一个 UI。
我遇到了这个问题,如果Value 与onChangeText 上将更新的值相同,我无法更改TextInput 上的文本。我打字时它被清空了。
我通过在更改值后立即添加 this.forceUpdate() 解决了这个问题,但这会使应用程序有点滞后,并且当我输入文本时地图上的标记会闪烁。
该值有时由代码更改,但有时由用户编辑并由代码读取。处理这个问题的正确方法是什么? forceUpdate 感觉不对……
<TextInput
keyboardType={'numeric'}
style = {styles.textInput}
value = {this.state.tmpCustomer.phoneNumber}
onChangeText ={(text) => {this.state.tmpCustomer.phoneNumber=text; this.forceUpdate()}}
/>
【问题讨论】:
-
也许
setState会起作用?我如何setState对象内的值 (tmpCustomer) ?我试过了,但出现错误(意外令牌):onChangeText ={(text) => this.setState({tmpCustomer: { phoneNumber: text }); }
标签: android user-interface reactjs native textinput