gpt4 book ai didi

ios - 在 iOS 中设置状态时 React Native TextInput 不更新

转载 作者:行者123 更新时间:2023-12-01 16:22:43 31 4
gpt4 key购买 nike

我在 iOS 中遇到了这个问题,在这个链接上做了同样的事情 React Native TextInput that only accepts numeric characters 但在 iOS 设备中没有解决

通过设置不反射(reflect)在 TextInput 中的状态进行更改,下面是我的代码:

constructor(props) {
super(props);
this.state = {
enteredMobile: '',
};}

onChanged(text){
this.setState({
enteredMobile: text.replace(/[^0-9]/g, ''),
});
}

我的文本输入

<TextInput
placeholderTextColor="lightgrey"
placeholder="Enter mobile no."
keyboardType = 'numeric'
maxLength={10}
style={{height: 40,top:140, left :94,width:500, borderColor: 'white', borderWidth: 1}}
onChangeText={(text) => this.onChanged(text)}
value = {this.state.enteredMobile}
/>

您可以在表格下方的图片中看到更新的那个,但它没有更新 TextInput 本身。

enter image description here

最佳答案

Pankaj 您必须在 onChanged 函数中使用 ES6 JS 进行编码,因为有时它在 ES5 语法中不起作用。

Try this one

constructor(props) {
super(props);
this.state = {
enteredMobile: '',
};
}

onChanged = (text) => {
this.setState({
enteredMobile: text.replace(/[^0-9]/g, ''),
});
}

我的文本输入

<TextInput
placeholderTextColor="lightgrey"
placeholder="Enter mobile no."
keyboardType = 'numeric'
maxLength={10}
style={{height: 40,top:140, left :94,width:500, borderColor: 'white', borderWidth: 1}}
onChangeText={(text) => this.onChanged(text)}
value = {this.state.enteredMobile}
/>

关于ios - 在 iOS 中设置状态时 React Native TextInput 不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50654352/

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