Search code examples
gojs

Custom linkDataArray GoJs


I have defined a GraphLinksModel like this:

  $(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
    });

This generates an output:

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

It is possible to generate this output, but with the javascript objects which are referencing inside it? Like this:

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

The purpose of this would be having the linked nodes without making any processing.

Thanks in advance


Solution

  • Answer from the forum of GoJS:

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

    "No, that is not valid JSON-format text. Also, I do not think it makes sense to put node definitions in links. They should be in the Model.nodeDataArray, so that they can be shared by all references from links."