我正在尝试在我的新 Android 应用程序中创建一个 SearchBar
组件。
我是 React-Native 的新手,所以我采用了这种样式将 text
传递给我称之为 _changeInput()
的本地函数。通过任务是正确的,但当我尝试添加 setTimeout
时,我的代码被破坏,并且我的 setTimeOut
不起作用。
目标:我想在 1 秒后将 TextInput
值传递给 _changeInput()
。
请参阅下面的代码,如果可以的话请帮助我:
...
constructor(props) {
super(props);
this.state = {
isLoading : false
}
lastTimeout = setTimeout;
}
_changeInput(text) {
Alert.alert('OoopS', text )
}
render() {
return(
...
<TextInput
numberOfLines={1}
returnKeyType="search"
onChangeText={ (text) => {
clearTimeout(this.lastTimeout);
this.lastTimeout = setTimeout(() => {this._changeInput(text)} ,1000)
} }
/>
...
最佳答案
关于javascript - React-Native 的 TextInput 组件中的 SetTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48718799/