GoJS中如何动态添加Node数据和Link数据?

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

 myDiagram.model = new go.GraphLinksModel(
[

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

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

我需要动态添加更多值,我应该怎么做?

节点数据(来源:GoJS docs, class Model):

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

Link 数据(来源: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.

从对象列表动态添加到 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