I tried several things and always I get a null, so I’m unable to get a Link object from diagram using findLinkForData method. This is a TypeScript code snippet:
static getLinkData(fromTo: string) : any {
var json = JSON.parse(VisualDesigner.diagram.model.toJson());
var linkArray: any[] = json['linkDataArray'];
var link: any;
for (var i = 0; i < linkArray.length; i++) {
if (linkArray[i].from == fromTo || linkArray[i].to == fromTo) {
link = linkArray[i];
break;
}
}
if (linkArray.length > 0) { // this is only for debug purpose
console.log("link: " + link.from);
console.log("link: " + VisualDesigner.diagram.findLinkForData(linkArray[0]));
}
return link;
}
First output shows link’s from data as expected but second one returns null.
Model’s output:
{ "class": "go.GraphLinksModel",
"nodeDataArray": [
{"key":101, "category":"root", "text":"ROOT1", "item":"mp_root", "taskType":0, "isGroup":true},
{"key":103, "category":"event", "text":"event1", "item":"mp_event", "taskType":0, "group":101, "loc":"-264 -189"},
{"key":108, "category":"share", "text":"event1", "item":"mp_share_new", "taskType":0, "gatewayType":1, "loc":"-352 62"}
],
"linkDataArray": [ {"from":108, "to":103, "category":"share"} ]}
What I have to do to get go.Link object using diagram.findLinkForData method?