0

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

4

1 回答 1

1

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

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

正如最后一节所建议的,当您有一个可编辑的TextBlock时,通常情况下您希望制作Binding TwoWay。这些是您希望自动保存在Model中的属性值吗?

于 2015-11-05T03:57:33.793 回答