How to add Node data and Link data dynamically in GoJS?

穿精又带淫゛_ 提交于 2020-01-14 07:51:30

问题


 myDiagram.model = new go.GraphLinksModel(
[

  { key: "Alpha", color: "lightblue" },
  { key: "Delta", color: "pink" }

],
[
  { from: "Alpha", to: "Alpha" },
  { from: "Delta", to: "Alpha" }
]);

I need to add more values dynamically, how should I do this?


回答1:


Node data (source: GoJS docs, class Model):

If you want to add or remove node data from the nodeDataArray, call the addNodeData or removeNodeData methods.

Link data (source: GoJS docs, class GraphLinksModel):

If you want to add or remove link data from the linkDataArray, call the addLinkData or removeLinkData methods. If you want to modify the node a link connects to, call the setFromKeyForLinkData and/or setToKeyForLinkData methods.




回答2:


An example of dynamically adding from an object list to a 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


来源:https://stackoverflow.com/questions/28525407/how-to-add-node-data-and-link-data-dynamically-in-gojs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!