【发布时间】:2017-06-11 09:26:50
【问题描述】:
那个标题有点乱码,这可能是重复的,但我已经挖掘了一段时间。这一定很简单。这个问题的公认答案对我不起作用: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"
}
}
【问题讨论】:
标签: javascript electron vis.js