【发布时间】:2017-10-31 01:03:18
【问题描述】:
运行以下代码时出现以下错误:
TypeError: 无法读取未定义的属性“数据”
const elementsList = [
{data: {id: 'a'}},
{data: {id: 'b'}},
{data: {id: 'c'}},
{data: {id: 'ab', source: 'a', target: 'b', weight: 4}},
{data: {id: 'as', source: 'a', target: 'c', weight: 3}}
];
const testGraph = cytoscape({elements: elementsList});
const dijkstra = testGraph.elements().dijkstra('#a', () => {
return this.data('weight');
}, false);
这与 cytoscape 文档中描述的代码几乎完全相同,所以我不确定我哪里出错了。
当我在没有回调的情况下运行 dijkstra 时,我没有收到任何错误,我什至能够对返回的结果执行 pathTo() 和 distanceTo()。
FIDDLE
【问题讨论】:
标签: javascript graph-theory dijkstra cytoscape