在GOJS中编辑后从图中获取nodeDataArray

时间:2017-11-28 22:40:34

标签: javascript graph diagram gojs

我正在使用GoJS制作图表, 我允许textedit用于节点,以及稍后创建新节点和编辑节点和链接

        window.diagram =
$(go.Diagram, "myDiagramDiv",
{
  initialContentAlignment: go.Spot.Center, // center Diagram contents
  "undoManager.isEnabled": true, // enable Ctrl-Z to undo and Ctrl-Y to redo
});
           // the node template describes how each Node should be constructed
          diagram.nodeTemplate =
            $(go.Node, "Auto",  // the Shape automatically fits around the TextBlock
            $(go.Shape, "RoundedRectangle",  // use this kind of figure for the Shape
             // bind Shape.fill to Node.data.color
             new go.Binding("fill", "color")),
            $(go.TextBlock,
            { margin: 3 ,// some room around the text
               editable: true },  // permet de le modifier
            // bind TextBlock.text to Node.data.key
            new go.Binding("text", "key")),
         );
          diagram.linkTemplate =
            $(go.Link,
            $(go.Shape),                           // this is the link shape (the line)
            $(go.Shape, { toArrow: "Standard" }),  // this is an arrowhead
            $(go.TextBlock,                        // this is a Link label
            new go.Binding("text", "text"))
        );

我可以使用

获取对象
    window.diagram.GraphLinksModel.nodeDataArray

但即使在编辑图表后我也得到了相同的对象数组 编辑后获取nodeDataArray和linkDataArray的任何帮助吗?

1 个答案:

答案 0 :(得分:0)

我找到了答案, 我应该在绑定时添加一个函数

    $(go.TextBlock,
            { margin: 3 ,// some room around the text
               editable: true}, 
            // bind TextBlock.text to Node.data.key
            new go.Binding("text", "key").makeTwoWay()), // makeTwoWayis what i neededd
         );