GoJS自定义节点保存默认值

GoJS Custom node saves default values

本文关键字:默认值 保存 节点 自定义 GoJS      更新时间:2023-09-26

基于示例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字符串中。其他内容,如位置和链接,都会正确保存。我的自定义模板有问题吗?或者我如何保存对图中节点值的更改?

基本思想是,如果某些代码(可能是由于用户操作)更改了GraphObject的某些属性(如Node.locationTextBlock.text),并且您希望更改后的值反映在节点数据对象中,则在该属性上使用TwoWayBinding

有关数据绑定的详细信息,请访问http://gojs.net/latest/intro/dataBinding.html,尤其是最后一节。

正如最后一节所建议的,当您有一个可编辑的文本块时,通常情况下您希望使绑定双向。这些是您希望自动保存在模型中的属性值吗?