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

                />
...

最佳答案

这里 :-/

Check that your device's time matches that of your computer! This happened to me and took an unfortunately long while to debug haha

see more

所以我将时间更改为5000毫秒,并且工作正常

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

10-13 08:59