javascript - React-Native 的 TextInput 组件中的 SetTimeout

标签 javascript android reactjs react-native

我正在尝试在我的新 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)
                    } }

                />
...

最佳答案

这里:-/

检查您设备的时间是否与计算机的时间匹配!这发生在我身上,不幸的是花了很长时间来调试哈哈

see more

所以我将时间更改为 5000 毫秒,效果很好

关于javascript - React-Native 的 TextInput 组件中的 SetTimeout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48718799/

相关文章:

javascript - 根据外部 javascript 文件中的单选按钮单击更改输入文本

java - quickblox android中的多个附件

java - 如何获取android cpu型号名称?

javascript - 'this' 未定义 - ReactJS

javascript - 如何在 React 中使用 POST 方法将对象添加到数据库?

javascript - Node.js发送带base64解码字符的POST请求时,出现无效字符错误

javascript - 在 Bootstrap 2.3.2 中创建全页宽度下拉菜单

javascript - Crossfilter.js 按多个分类轴分组

Android Google Map v2 不显示 map

reactjs - Appsync更新和删除突变不起作用