【问题标题】:How to add new property to node template that will be saved to Json diagram model using GoJS?如何使用 GoJS 将新属性添加到将保存到 Json 图模型的节点模板?
【发布时间】:2017-06-15 12:30:36
【问题描述】:

我的意思是左侧调色板和右侧图表区域的应用程序类型。

例如我有以下节点模板:

var inputTemplate =
    $(go.Node, "Spot",
    nodeStyle(),
    $(go.Shape, "Circle", shapeStyle1(),
        { fill: red }),  // override the default fill (from shapeStyle1()) to be red
    $(go.Shape, "Rectangle", portStyle(false),  // the only port
        { portId: "", alignment: new go.Spot(1, 0.5) }),
    {
        doubleClick: function (e, obj) {
            window.open("http://www.microsoft.com", "_blank");
    }}
    );

并且想要在节点级别添加 Guid 属性,当我们使用 toJson 函数保存图表时,该属性将出现在 Json 模型中。怎么做?

【问题讨论】:

    标签: json gojs


    【解决方案1】:

    您可以向模型数据添加任意数量的属性。只需确保属性名称不以下划线(“_”)开头,并且属性值是 JSON 可序列化的。在https://gojs.net/latest/api/symbols/Model.html 阅读要求。

    如果您想使用 GUID 作为键值,请首先确保所有现有节点数据都具有唯一的 GUID 字符串值。并将 Model.makeUniqueKeyFunction 设置为返回新 GUID 字符串的函数。

    这是https://forum.nwoods.com/t/how-to-add-new-property-to-node-template-that-will-be-saved-to-json-diagram-model/8726 的副本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-27
      • 1970-01-01
      • 1970-01-01
      • 2012-09-25
      • 1970-01-01
      • 2020-04-29
      相关资源
      最近更新 更多