javascript - 正确传入结构(js)

标签 javascript bixby

在正确地将数据传递到结构中时遇到一些问题

这是结构

enter image description here

这就是我进入的方式

var dates = require('dates');

module.exports.function = function getStart() {
  var optionList = [
  {option : "Latest headlines"},
  {option : "Latest news"},
  {option : "Top headlines"},
  {option : "Top news"}
]
  var currentTimeHour = dates.ZonedDateTime.getHour
  var timePeriod = "";

  if (currentTimeHour == 0 && currentTimeHour <= 12) {
    timePeriod = "M"//Morning
  } else if (currentTimeHour >= 13 && currentTimeHour <= 20) {
    timePeriod = "A"//Afternoon
  } else if (currentTimeHour <=23){
    timePeriod = "N"//Night
  }else {
    timePeriod = null
  }

  var menu = {};

  optionList.option.forEach(function(value,index,array){
    menu[index] = {
      whatuserwant : optionList[index],
      timePeriod : timePeriod
    }

  });

  return menu

}

并弹出错误

enter image description here

我哪里出错了

还有一个问题,我的 currentTimeHour 的 if-else 条件写得正确吗?

问候。

最佳答案

forEach 是在数组上定义的,而 optionList.option 不是数组。

尝试仅使用 optionList

optionList.forEach(function(value,index,array){
        menu[index] = {
          whatuserwant : value.option,
          timePeriod : timePeriod
        }
      });

关于javascript - 正确传入结构(js),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60864592/

相关文章:

javascript - 自动执行匿名 JavaScript 函数的括号位置?

javascript - 如何使用 jQuery 根据这些 HTML 元素的总高度将所有 HTML 元素包装在 DIV 中?

javascript - 动态嵌套的 React 组件

javascript - 将两个值传递到 super 账本结构查询的语法?

bixby - 有没有办法将 Bixby 日志保存到外部文件?

Javascript,无法减去值

Bixby:无法打印消息

bixby - 在 Bixby 中,如何让用户按顺序翻阅一系列结果?

javascript - Bixby,单个 Javascript 函数中的多个 HTTP 调用?

javascript - 如何在json数组中搜索文本