[英]Go.JS Diagram Add Javascript Array Object Not Working As Expected No Hash ID
This must be a formatting issue, but my graph is not accepting new data from the real source... I noticed there is not hash ID being generated by Go.js这一定是格式问题,但我的图表不接受来自真实来源的新数据......我注意到 Go.js 没有生成 hash ID
function updateGraph(node_list,myDiagram){
var model = $(go.TreeModel);
//add some dummy data
model.nodeDataArray =
[
{ key: 1, parent: 1, color: "lightblue"},
{ key: 2, parent: 1 , color: "lightblue"},
{ key: 3, parent: 2, color: "lightblue"}
];
//add real data
for(let id = 1; id < node_list.length; id++){
model.nodeDataArray.push({key: node_list[id].getNodeID(), parent: node_list[id].getNodeID(), color: "lightblue"});
}
console.log(model.nodeDataArray);
myDiagram.model = model;
}
Console:安慰:
0: {key: 1, parent: 1, color: "lightblue", __gohashid: 409}
1: {key: 2, parent: 1, color: "lightblue", __gohashid: 410}
2: {key: 3, parent: 2, color: "lightblue", __gohashid: 411}
3: {key: "step_02_set_incoming_file_permissions", parent: "step_02_set_incoming_file_permissions", color: "lightblue"}
4: {key: "step_025_truncate", parent: "step_025_truncate", color: "lightblue"}
5: {key: "step_03_extract_item_sold_details", parent: "step_03_extract_item_sold_details", color: "lightblue"}
However, if I set the dummy data to hardcoded values being printed out by the console:但是,如果我将虚拟数据设置为控制台打印出的硬编码值:
model.nodeDataArray =
[
{key: "step_02_set_incoming_file_permissions", parent: "step_01_starting_email", color: "lightblue"},
{key: "step_025_truncate", parent: "step_02_set_incoming_file_permissions", color: "lightblue"},
{key: "step_03_extract_item_sold_details", parent: "step_025_truncate", color: "lightblue"}
];
I get an output with hash id's:我得到一个 output 和 hash id:
Ok, so Go.JS requires another function to add data properly.好的,所以 Go.JS 需要另一个 function 才能正确添加数据。 You can't just feed it dymanic object for some reason... Calling the method
addNodeData
as per Go.JS documentation fixed the graphing issue!出于某种原因,您不能只喂它动态 object ... 按照Go.JS 文档调用方法
addNodeData
修复了图形问题!
model.addNodeData({key: node_list[id].getNodeID(), parent: node_list[id].getNodeID(), color: "lightblue"});
model.addLinkData( { from: node_list[id].getNodeID(), to: node_list[id].getNextNode() } ); //link data
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.