- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这个标题有点乱码,这可能是重复的,但我已经挖掘了一段时间了。这一定非常简单。关于这个问题的公认答案对我不起作用:How to declare and use the name of a function from a json object?
任务:我正在尝试将 Vis.js
时间轴的设置数据外部化到 JSON 文件中。除了函数引用“orderByID”和“visTemplate”之外,数据集没有问题,所有选项也没有问题。这些是我定义的函数,它们存在于我正在处理 JSON 数据的脚本中。
当我尝试使用 JSON 而不尝试转换它时,Vis.js
会提示。当我使用下面的代码尝试上述问题的答案时,我得到了图像中显示的错误。
这是在 Electron
中,脚本是通过 index.html 中的脚本标签加载的。
我等待这个简单问题的一行答案,这个问题已经花了很多时间来描述。 😉
<小时/>console.log(' timelineOptions.order', timelineOptions.order);
console.log(' timelineOptions.template', timelineOptions.template);
console.log('this', this);
console.log('window', window);
timelineOptions.order = window[timelineOptions.orderByID];
timelineOptions.template = window[timelineOptions.visTemplate];
<小时/>
<小时/>
"timelineOptions": {
"order": "orderByID",
"selectable": true,
"zoomable": false,
"width": "100%",
"height": "90%",
"minHeight": 700,
"format": {
"minorLabels": {
"hour": "HH\\h"
}
},
"margin": {
"axis": 20,
"item": 20
},
"start": "2016-12-30",
"end": "2017-01-4",
"template": "visTemplate",
"showCurrentTime": false,
"dataAttributes": "all",
"timeAxis": { "scale": "day", "step": 1 },
"orientation": {
"axis": "top",
"item": "top"
}
}
最佳答案
不确定您是否在窗口对象上设置了正确的引用,但您的代码不应该读取:
timelineOptions.order = window[timelineOptions.order];
您引用了字符串值orderByID,而不是用于设置对象的属性名称。
关于javascript - 将函数的名称存储在 JSON 文件中,然后能够从脚本中加载和调用它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41864471/
我正在开发一个需要能够平均三个数字的 Facebook 应用程序。但是,它总是返回 0 作为答案。这是我的代码: $y = 100; $n = 250; $m = 300; $number = ($y
我只是无法弄清楚这一点,也找不到任何对我来说有意义的类似问题。我的问题:我从数据库中提取记录,并在我的网页上以每个面板 12 条的倍数显示它们。因此,我需要知道有多少个面板可以使用 JavaScrip
我是一名优秀的程序员,十分优秀!