Go.JS 图添加 Javascript 数组对象未按预期工作 无哈希 ID

Go.JS Diagram Add Javascript Array Object Not Working As Expected No Hash ID

这一定是格式问题,但我的图表不接受来自真实来源的新数据...我注意到 Go.js

没有生成哈希 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;
    }

控制台:

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"}


但是,如果我将虚拟数据设置为控制台打印的硬编码值:

  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"}
    ];

我得到一个带有哈希 ID 的输出:

好的,所以 Go.JS 需要另一个函数来正确添加数据。由于某种原因,您不能只给它提供动态对象...根据 Go.JS documentation 调用方法 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