无法读取null的属性'arrayOfDay1'

时间:2018-10-31 10:29:06

标签: react-native

如何解决?

我检查数组不为null并转到

但是我的应用出现错误

   if (this.state.arrayOfDay1.length === 0 || this.state.arrayOfDay1 === 'undefined') {
            console.log(18);
                var result = (this.state.arrayOfDay1).includes(i + 1);
                if (result === true) {
                    state = 1;
                    // pic = require('../upload/see.png');
                    // this.setState({ pic: require('../upload/see.png') });
                    // this.setState({ key: true });
                } else {
                    state = 0;
                    // pic = require('../upload/notSee.png');
                    // this.setState({ pic: require('../upload/notSee.png') });
                }

        }else {
            state = 0;
            console.log(1115);
        }

enter image description here

enter image description here

谢谢

:))))

编辑

我发现我的问题。 我忘了在状态之前插入

nicccce

2 个答案:

答案 0 :(得分:0)

将if条件更改为

if (this.state.arrayOfDay1.length != 0 && this.state.arrayOfDay1 != undefined && this.state.arrayOfDay1.length != null) {
            console.log(18);
                var result = (this.state.arrayOfDay1).includes(i + 1);
                if (result === true) {
                    state = 1;
                    // pic = require('../upload/see.png');
                    // this.setState({ pic: require('../upload/see.png') });
                    // this.setState({ key: true });
                } else {
                    state = 0;
                    // pic = require('../upload/notSee.png');
                    // this.setState({ pic: require('../upload/notSee.png') });
                }

        }else {
            state = 0;
            console.log(1115);
        }

答案 1 :(得分:0)

 if(this.state.arrayOfDay1.length !== 0 && this.state.arrayOfDay1 !== undefined ) {
            console.log(18);
                var result = (this.state.arrayOfDay1).includes(i + 1);
                if (result === true) {
                    state = 1;
                    // pic = require('../upload/see.png');
                    // this.setState({ pic: require('../upload/see.png') });
                    // this.setState({ key: true });
                } else {
                    state = 0;
                    // pic = require('../upload/notSee.png');
                    // this.setState({ pic: require('../upload/notSee.png') });
                }

        }else {
            state = 0;
            console.log(1115);
        }