GoJS Custom节点保存默认值

GoJS Custom node saves default values

基于示例http://gojs.net/latest/samples/flowchart.html我创建了如下所示的自定义节点模板。

myDiagram.nodeTemplateMap.add("Action-node",
    $(go.Node, "Spot", nodeStyle(),
        $(go.Panel, "Auto",
            $(go.Shape, "Rectangle",
                { minSize: new go.Size(40, 40), fill: "#FF9191", stroke: null }),
            $(go.Panel, "Vertical",
                $(go.TextBlock, "Start",
                {
                    font: "8pt Helvetica, Arial, sans-serif",
                    margin: 8,
                    stroke: lightText,
                    editable: true
                },
                new go.Binding("text")),
                $(go.TextBlock, "...",
                {
                    font: "8pt Helvetica, Arial, sans-serif",
                    margin: 8,
                    stroke: lightText,
                    editable: true
                },
                new go.Binding("text", "subtitle"))
            )
        ),
        // three named ports, one on each side except the top, all output only:
        makePort("T", go.Spot.Top, false, true),
        makePort("L", go.Spot.Left, true, false),
        makePort("R", go.Spot.Right, true, false),
        makePort("B", go.Spot.Bottom, true, false)
    ));

问题是调用

的保存按钮(save() 函数)
myDiagram.model.toJson(); 

仅将默认值保存到 json 字符串。位置和 link 等其他内容已正确保存。我的自定义模板有问题吗?或者我如何保存图表中节点值的更改?

基本思想是,如果某些代码(可能是因为用户操作)改变了一些GraphObject 属性(例如Node.locationTextBlock.text) 并且您希望更改的值反映在节点数据对象中,您使用 TwoWay Binding 属性.

http://gojs.net/latest/intro/dataBinding.html 阅读有关数据绑定的更多信息,尤其是最后一节。

如上一节所述,当您有一个 TextBlock editable 时,通常情况下您想要制作绑定双向。这些是您希望自动保存在 Model 中的 属性 值吗?