首页 > 解决方案 > 尝试在本机反应中推送元素时,推送不是功能

问题描述

我有以下代码:

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 条件。

我无法按我想要的方式推动它。有任何想法吗?

标签: javascriptreact-native

解决方案


推荐阅读