簡體   English   中英

React-Native的TextInput組件中的SetTimeout

[英]SetTimeout in TextInput component of 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)
                    } }

                />
...

這里 :-/

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

查看更多

所以我將時間更改為5000毫秒,並且工作正常

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM