我正在将节点和链接导出到这样的 json 对象,以便稍后将其写入磁盘。这是我加载时的数据:
{
"nodes": [
{
"id": "a1",
"type": "activity",
"loaded": true,
"style": {"label": "Testing ZoomCharts"}
},
{
"id": "o1",
"type": "organization",
"loaded": true,
"style": {"label": "Ophileon"}
}
],
"links": [{
"id": "l1",
"from": "o1",
"to": "a1",
"style": {"label": "Executes"}
}
}
当我从当前图表中获取节点和链接时,像这样
function exportNodes(){
var nodesandlinks = {"nodes":[],"links":[]};
nodesandlinks.nodes.push(chart._scene.data.nodes);
nodesandlinks.links.push(chart._scene.data.links);
alert(JSON.stringify(nodesandlinks));
}
它返回一个结果,我需要再次处理才能重新加载它,因为它具有每个节点作为属性。
{
"nodes": [{
"a1": {
"id": "a1",
"type": "activity",
"loaded": true,
"style": {"label": "Testing ZoomCharts"}
},
"o1": {
"id": "o1",
"type": "organization",
"loaded": true,
"style": {"label": "Ophileon"}
}
}],
"links": [{"l1": {
"id": "l1",
"from": "o1",
"to": "a1",
"style": {"label": "Executes"}
}}]
}
是否有另一种方法来检索节点?我已经试过了:
chart.data.nodes
TypeError: Cannot read property 'nodes' of undefined
chart.nodes
function (){return this._impl.scene.nodes()}