Dynamically created Context Menu

Hello,

I’m running into an issue wrapping my head around a problem that I have. I’m wanting to create a context menu with a different amount of buttons based on the nodeDataArray of the selected node. I have a availableTemplates array in my nodeDataArray, and I wish to loop through that array and bind a button for each one, but I’m not sure how.

Any sort of direction would be most helpful! Thanks!

This example ought to work, but it turns out that there is a bug in updating the contextMenu Adornment when the number of items in the menu decreases. We’ll fix that for the next baselevel.

diagram.nodeTemplate = $(go.Node, . . ., { contextMenu: $(go.Adornment, "Vertical", new go.Binding("itemArray", "menudata"), { itemTemplate: $("ContextMenuButton", $(go.TextBlock, new go.Binding("text", "")), { click: function(e, obj) { alert(obj.data); } } ) }) }, . . .);</p><p>var nodeDataArray = [ { . . ., menudata: ["one", "two", "three"] }, . . . ];

That example works great, except for the bug you mentioned. Any suggested work-around until the update?

Thanks for the quick reply!

version 1.2.7

Oh. Well then. Thank you!