arrays - 无法读取 JSX 中数组的长度(React-Redux)
问题描述
很简单的问题。我正在尝试读取此对象数组中“长度”变量的值(参见图 1)
我的代码
const mapStateToProps = (state, ownProps) => {
const lecture = state.firestore.ordered.lectures;
const length = lecture.length;
return {
length: length,
}
}
解决方案
在写这个问题时,我找到了解决方案:
解决方案代码
const mapStateToProps = (state, ownProps) => {
const length = state.firestore.ordered.lectures && state.firestore.ordered.lectures.length;
return {
length: length,
}
}
推荐阅读
- javascript - 如何检测广告?
- python - Sublime Text 插件设置:未加载
- sql - SQL 触发器插入
- azure-active-directory - Azure Active Directory B2C 自定义错误页面被忽略
- javascript - 在 typedoc 中标记/生成方法链接?
- azure-devops - 防止 VSTS 中的后期构建事件
- mysql - LEFT JOIN 用于两个不同的值
- node.js - 每个项目的 docker 注册表
- ios - 1天IOS safari - AngularJS
- .htaccess - .htaccess 将 Cookie 与文件/链接中的数据进行比较