How to differentiate nodes?

How can we differentiate the nodes ? Is there any property like “id” to set/get in a node to identify it.

<p style=“margin: 0in 0in 0pt;” =“Msonormal”>You can use whatever string-or-number property on your data that
you like.<?: prefix = o ns = “urn:schemas-microsoft-com:office:office” /><o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”>By default a Model assumes the property is named “key”, but you
can change that to be “id” by setting Model.nodeKeyProperty to “id”.<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”><o:p> </o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”>It appears that you are not using models. I recommend that
you do.<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”>That approach keeps the application-specific data to a minimum
while separating the appearance and behavior from the data.<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”><o:p> </o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”>The appearance of nodes and links can be defined declaratively.<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”>The behavior is defined by setting properties or providing
JavaScript functions.<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”>Both the appearance and behavior are defined in JavaScript that
goes along with your HTML/CSS pages.<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”>Use data binding to customize the appearance and behavior of
each node according to your data.<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”><o:p> </o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”>The model and its data are simple JavaScript objects and can be
persisted in JSON format by calling Model.toJson and Model.fromJson. Or
save and load it in whatever format you want.<o:p></o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”><o:p> </o:p>

<p style=“margin: 0in 0in 0pt;” =“Msonormal”>I suggest you read: http://gojs.net/beta/intro/usingModels.html
and http://gojs.net/beta/intro/dataBinding.html
.<o:p></o:p>

Hi Walter,

I have tried to do what has been been mentioned in this post Model.nodeKeyProperty to “id”.


But with this change my diagram links are not getting painted at all. Is there any thing I am missing?


Thanks,
Nitin

If you simplify to the smallest possible model, what data does it have?

Hi Walter,

Below is the smallest possible simplified model,

nodeDataArray = [{
nodeId: “START”,
text:“Start”
},
{
nodeId: “1”,
text:“Node One”
}]

linkDataArray=
[{
from:“START”, to:“1”
}]

one thing I am using Model.nodeCategoryProperty also mapped to the nodeId aka key in my case.

Thanks,
Nitin

What properties have you set on the model?

I assume with the properties you mean below

diagram.model.nodeKeyProperty = “nodeId”;

diagram.model = new go.GraphLinksModel(nodeDataArray, linkDataArray);

diagram.model.nodeCategoryProperty = “nodeId”;

Thanks,
Nitin

Don’t set nodeCategoryProperty to be the same property as the node key.

That also doesn’t work:(

How is this different from any of the minimalist samples?
Both nodes show, don’t they?
diagram.links.count = ?
diagram.links.first().actualBounds = ?
diagram.linkTemplate = ?