Key of a Node

How to find a key of a node?

In my project I have two similar nodes of diagram. There are some attributes associated to these two nodes but there values are different. Somehow I want to know the key associated to these nodes, so that I can set the attributes values based on that.

Please let me know
Thanks.

http://www.gojs.net/latest/api/symbols/Model.html#getKeyForNodeData

or maybe just node.data.key

A piece of code would be more helpful.

Please share if possible.

I did: “node.data.key”, assuming “node” evaluates to the Node that you care about.

I found the key using the following code.

var object = elem.findObject(“SHAPE”); //where SHAPE is name of any selected node.
var key = object.part.data.key;

Thanks Walter for giving me the hint.

If “elem” is a selected Node, then “elem.data.key” would get you the node’s key.

Searching the visual tree of the Node for a particular GraphObject named “SHAPE” and then walking back up the visual tree by getting its “.part” is unnecessary. And it might fail if there is no object named “SHAPE”.