Get node key in called function on click

Hello,

I would like to call a function when a node is clicked and send the function called the key of the clicked node. I have the first part that calls the function. I can also receive something in the called function but I do not know how to get the key from the node object in the called function.

How do I get the key?

Here is the node information and the called function:

myDiagram.nodeTemplate =
graphObjectMake(go.Node, “Table”,
{
<span =“Apple-tab-span” style=“white-space:pre”> click: getNodeData
},
{ locationObjectName: “BODY”,
locationSpot: go.Spot.Center,
selectionObjectName: “BODY”,
selectionAdornmentTemplate:
graphObjectMake(go.Adornment, “Auto”,
graphObjectMake(go.Shape, “Rectangle”,
{ stroke: “dodgerblue”,
strokeWidth: 3,
fill: null }),
graphObjectMake(go.Placeholder)
)

        },
        {
            mouseDragLeave: function (e, node, next) {
            },
            mouseDrop: function (e, node) {
            }
        },
        new go.Binding("key", "text", go.Point.parse).makeTwoWay(go.Point.stringify),

        // the body
        graphObjectMake(go.Panel, "Auto",
            { row: 1, column: 1, name: "BODY",
                stretch: go.GraphObject.Fill },
                graphObjectMake(go.Shape, "RoundedRectangle",
                { fill: "blue",
                    minSize: new go.Size(135, 65) },
                new go.Binding("fill", "color").makeTwoWay()),
                graphObjectMake(go.Panel, "Table",
                {maxSize: new go.Size(135, 65),
                    defaultAlignment: go.Spot.Center },
                graphObjectMake(go.RowColumnDefinition, { column: 1, row: 3, width: 10 }),
                graphObjectMake(go.TextBlock,"name",
                    { margin: 5,
                        row: 1, column: 0,
                        editable: false,
                        stroke:"SlateGrey",
                        font: "11pt sans-serif",
                        textAlign: "center" },
                    new go.Binding("text", "name").makeTwoWay())

<span =“Apple-tab-span” style=“white-space:pre”> )
) // end Auto Panel body
); // end Node

function getNodeData(node)
{

<span =“Apple-tab-span” style=“white-space:pre”> //<span =“Apple-tab-span” style=“white-space:pre”> <How do I get the key of the node variable?>
var sd = “dsafhj”;
var hg = sd;

}

Lots of samples do things like that. Have you searched the samples?

For example, http://gojs.net/latest/samples/classHierarchy.html does something similar to what you want, except that it uses doubleClick instead of click.

Also, please read http://gojs.net/latest/intro/events.html for more information about event handlers such as GraphObject.click.

Thanks Walter!

Based on where you pointed me, I have two examples here if anyone else runs into this issue.

Example of calling a function on click in the nodetemplate of the diagram.
{ click: function(e, obj) { getNodeData("Clicked on " + obj.part.data.key); }},

Example of using a listener:

myDiagram.addDiagramListener(“ObjectSingleClicked”,
function(e) {
var part = e.subject.part;
<span =“apple-tab-span”=“” style=“white-space:pre”> //part.data is the node object
if (!(part instanceof go.Link)) getNodeData1("Clicked on " + part.data);
});