【问题标题】:GoJS Custom node saves default valuesGoJS 自定义节点保存默认值
【发布时间】:2016-02-05 00:48:45
【问题描述】:

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

【问题讨论】:

    标签: javascript json gojs


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2023-04-04
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多