onchange不起作用,

时间:2018-07-26 20:47:33

标签: javascript reactjs react-native react-navigation

在我的本机代码中,我将参数设置为bx,其中包含一个textinput,我将其用作导航的标题,但现在我想在屏幕上进行更新,即更改textinput,但是引发错误undefined is not an object,请有人帮忙提供解决方案,以解决我在更改文字输入后如何成功更新屏幕的问题

 onUpdate = (e) => {
    this.setState({
        search: e.target.value
    });
    let db = SQLite.openDatabase({
        name: 'test.db',
        createFromLocation: "~Herbo.db",
        location: 'Library'
    }, this.openCB, this.errorCB);
    db.transaction((tx) => {
        tx.executeSql("SELECT * FROM data where name like '" + this.state.search + "' ", [], (tx, results) => {
            console.log("Query completed");
            var len = results.rows.length;
            for (let i = 0; i < len; i++) {
                let row = results.rows.item(i);
                this.setState(prevState => ({
                    record: [...prevState.record, row],
                    pressed: [...prevState.pressed, false]
                }));
                console.log(`Record: ${row.name}`);
                //this.sleep(2);
                //this.setState({record: row});
            }
            this.setState({loader: false})
        });
    });
};
_setNavigationParams() {
    let bx = <TextInput placeholder="Search for your herbs by name,type..." value={this.state.search} onChange={this.onUpdate.bind(this)}
                        underlineColorAndroid={'transparent'}
                        style={BackStyles.textBox}/>
    this.props.navigation.setParams({
        bx
    });
}
static navigationOptions = ({navigation, navigationOptions}) => {
    const {params} = navigation.state.params || {};
    return {
         headerTitle: params.bx};
    //   header:  null
};
componentWillMount() {
    this._setNavigationParams();
}
constructor(props) {
    super(props);
    this.state = {
        record: [],
        header: null,
        loader: true,
        pressed: {},
        ar: [],
        search: ''
    };

    let db = SQLite.openDatabase({
        name: 'test.db',
        createFromLocation: "~Herbo.db",
        location: 'Library'
    }, this.openCB, this.errorCB);
    db.transaction((tx) => {
        tx.executeSql('SELECT * FROM data', [], (tx, results) => {
            console.log("Query completed");
            var len = results.rows.length;
            for (let i = 0; i < len; i++) {
                let row = results.rows.item(i);
                this.setState(prevState => ({
                    record: [...prevState.record, row],
                    pressed: [...prevState.pressed, false]
                }));
                console.log(`Record: ${row.name}`);
                //this.sleep(2);
                //this.setState({record: row});
            }
            this.setState({loader: false})
        });
    });
}

0 个答案:

没有答案