Reputation: 75
I'm using GoJs Flow builder and I've been trying to alert the IDs of the selected nodes (the blue ones) when clicking on a button inside the menu (that opens when you right-click on an object):
That is, I want it to alert "1,2,3" when clicked "Alert IDs".
Any help would be greatly appreciated!
Upvotes: 1
Views: 2471
Reputation: 4106
myDiagram.nodeTemplate.contextMenu =
$(go.Adornment, "Vertical",
$("ContextMenuButton",
$(go.TextBlock, "Alert keys"),
{
click: function(e, obj) {
var msg = "";
e.diagram.selection.each(function(n) {
if (!n instanceof go.Node) return;
if (msg.length > 0) msg += ", ";
msg += n.data.key;
})
alert(msg);
}
}
),
$("ContextMenuButton",
. . .
Read more about collections at http://gojs.net/latest/intro/collections.html.
Also, to answer your question more literally:
myDiagram.selection.toArray()
will return a JavaScript Array of selected Parts, on which you could use Array functions.
Upvotes: 2