myDiagram.model = new go.GraphLinksModel(
[
{ key: "Alpha", color: "lightblue" },
{ key: "Delta", color: "pink" }
],
[
{ from: "Alpha", to: "Alpha" },
{ from: "Delta", to: "Alpha" }
]);
我需要动态添加更多值,我该怎么做?
答案 0 :(得分:11)
节点数据(来源:GoJS docs, class Model):
如果要从nodeDataArray添加或删除节点数据,请调用addNodeData或removeNodeData方法。
关联数据(来源:GoJS docs, class GraphLinksModel):
如果要添加或删除linkDataArray中的链接数据,请调用addLinkData或removeLinkData方法。如果要修改链接所连接的节点,请调用setFromKeyForLinkData和/或setToKeyForLinkData方法。
答案 1 :(得分:0)
从对象列表动态添加到GraphLinksModel的示例:
var model = new go.GraphLinksModel();
for(let id = 1; id < node_list.length; id++){
model.addNodeData( { key: node_list[id].getNodeID(), color: "lightblue" } );
model.addLinkData( { from: node_list[id].getPreviousNode(), to: node_list[id].getNodeID() } );
}
myDiagram.model = model;
console.log(model.nodeDataArray); //to see data