且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

React Native Picker selected value 给出了 undefined is not an object 错误

更新时间:2022-01-17 22:28:21

我想你忘记在Buttonbindevent,使用这部分:

I think you forgot to bind the event in Button, Use this part:

<Button
   onPress = {this.submit.bind(this)}
   title = {this.state.buttonvalue}
   color = '#FF7323'>
</Button>

你可以在constructor中定义binding:

constructor(props) {
    super(props);
    this.state = {
        remarkstext: 'Remarks' ,
        buttonvalue: 'Submit' ,
        selected1: '--Select--',
        selected2: '--Select--',
        color: 'red',
        mode: Picker.MODE_DIALOG,
    };
    this.submit = this.submit.bind(this);
}

Update- fetch 调用模式:

fetch(url)
    .then(response => response.json())
    .then(response => {
       console.log(response);
    })
    .catch( error => 
        console.log('There has been a problem with your fetch operation: ' + error.message);
    )

您需要以这种方式捕获异常和错误.

You need to Catch the exceptions and errors in this way.