自定义linkDataArray GoJs

时间:2017-10-13 07:02:19

标签: gojs

我已经定义了一个这样的GraphLinksModel:

  $(go.GraphLinksModel,
    {
      archetypeNodeData: {},
      linkFromPortIdProperty: 'source',
      linkFromKeyProperty: 'sourceColumn',
      linkToPortIdProperty: 'destination',
      linkToKeyProperty: 'destinationColumn',
      'Changed': (e) => {
        if (e.isTransactionFinished) {
          console.log('Changed ' + this.diagram.model.toJson());
        }
      },
      nodeDataArray: this.visualOrigins,
      linkDataArray: this.relations
    });

这会生成一个输出:

 "linkDataArray": [ 
    {"source":"Record1", "sourceColumn":"field1", "destination":"Record2", 
    "destinationColumn":"fieldA"}
 ]}

可以生成此输出,但是使用在其中引用的javascript对象?像这样:

 "linkDataArray": [ 
    {"source":"Record1", 
     "sourceObjectNode": {sourceObjectReferenced},
     "sourceColumn":"field1",
     "sourceColumnObjectNode": {sourceColumnObjectNodeReferenced},
     "destination":"Record2", 
     "destinationObjectNode": {destinationObjectNodeReferenced},
     "destinationColumn":"fieldA",
     "destinationColumnNode": {destinationColumnObjectNodeReferenced}}
 ]}

这样做的目的是让链接节点不进行任何处理。

提前致谢

1 个答案:

答案 0 :(得分:0)

来自GoJS论坛的答案:

https://forum.nwoods.com/t/insert-node-object-inside-linkdataarray/9395

“不,这不是有效的JSON格式文本。 另外,我认为将节点定义放在链接中是没有意义的。它们应该在Model.nodeDataArray中,以便链接中的所有引用都可以共享它们。“