I’m having trouble to link nodes using a function.
The code I use is:
var nodeArray = [ {key:1,name:"name1",child:[2,3]}, {key:2,name:"name2",child:[3]}, {key:3,name:"name3",child:[]}]; myDiagram.model.nodeDataArray = nodeArray; var linkArray = []; var nit = myDiagram.nodes; var nodes = new go.List(go.Node); nodes.addAll(nit); for (var i = 0; i < nodes.count; i++) { var fro = nodes.elt(i); for (var j=0; j<fro.data.child.length; j++){ var to = fro.data.child[j]; linkArray.push({from:fro.data.key, to:to}); } } myDiagram.model.linkDataArray = linkArray;
However, this doesn’t connect the nodes. I tried without the lists (single child per node) and this worked fine. I’m new to JS and I’m not sure how to generate a useful error message…
I took the fro.data.key idea from the layered digraph sample:Layered Digraph Layout.
It seems to be the way to access the data of the nodes.
I don’t know how to check the values of the variables (I do realize this is a very noobish thing); I write the code in a notepad and then test the code in my browser. Any suggestions on imporved debugging would be greatly appreciated.