javascript - 尝试在本机反应中推送元素时,推送不是功能
问题描述
我有以下代码:
const timeframes = {};
let calendars = this.state.calendars;
for(let i = 0; i < this.state.rows; i++) {
if(timeframes[calendars[i][0]]) {
timeframes[calendars[i][0]].push(calendars[i][0]); //THROWS ERROR
} else {
timeframes[calendars[i][0]] = calendars[i][1];
}
}
我只是在尝试构建某种 JSON 样式的数据。例如日历可能如下所示:
[["Lunes", "mañana"], ["Lunes", "tarde"], ["Martes", "mañana"], ["Jueves", "mañana"]]
因此,我在该代码中尝试将值“mañana”和“tarde”设置为键“Lunes”。其他值在此示例中不是问题,因为它们不属于引发错误的 if 条件。
我无法按我想要的方式推动它。有任何想法吗?
解决方案
推荐阅读
- python-3.x - ValueError: Layersequential_2 需要 1 个输入,但它接收到 2 个输入张量。收到的输入
- python - 如何使 pandas 中的数据透视表表现得像 Excel 中的数据透视表?
- c# - “使用命名空间”指令只能应用于命名空间;“随机”是一种类型而不是命名空间。考虑使用“使用静态”代替
- xcode - 对于非常大的应用程序,如何修复因“ARM64 分支超出范围”而失败的构建?
- java - 使用条件更新外键值时出现问题
- javascript - 使用链接触发模态窗口
- reactjs - 带有参数问题的嵌套 React 路由
- automation - 机器人框架字符串格式化
- python - 在 Django 中刷新页面时避免运行脚本
- android - 需要为 Android 项目使用 Firebase 功能的建议