0

很简单的问题。我正在尝试读取此对象数组中“长度”变量的值(参见图 1)

在此处输入图像描述

我的代码

const mapStateToProps = (state, ownProps) => {

    const lecture = state.firestore.ordered.lectures;
    const length = lecture.length;

    return {

        length: length,

    }
}
4

1 回答 1

0

在写这个问题时,我找到了解决方案:

解决方案代码

const mapStateToProps = (state, ownProps) => {


    const length = state.firestore.ordered.lectures && state.firestore.ordered.lectures.length;



    return {

        length: length,

    }
}
于 2020-08-06T22:22:47.410 回答