ContextMenu click error

i’m try to set a context menu to exclude a node like this

$$(“ContextMenuButton”,
$$(go.TextBlock, “exclude”),
{ click: function(e, obj) {
<span =“apple-tab-span”="" style=“white-space:pre”> myDiagram.startTransaction(“exclude a node”);
<span =“apple-tab-span”="" style=“white-space:pre”> obj.part.containingGroup=null;
<span =“apple-tab-span”="" style=“white-space:pre”> myDiagram.commitTransaction(“exclude a node”);
<span =“apple-tab-span”="" style=“white-space:pre”> } })

and i have the error like this:

Uncaught Error: The property [object Object] is read-only and cannot be set to null

WARNING: In ToolManager.doMouseDown: UndoManager.transactionLevel is not zero

i don’t understand why the obj.part.containingGroup is read-only and the warning too, can you explain more about this?


One more thing, i want the context menu only show the “exclude” whenever i rightclick on a node that is already contained in a group. How can i do that too?


thanks

The “obj” argument to the GraphObject.click function is the object on which the click property was set where a click occurred within its visual tree. In your case, that means the “obj” should be the whole button, a Panel.

But that button is just part of the whole context menu, which is an Adornment on whatever Part you defined it to be on. So the expression “obj.part” will evaluate to that Adornment. But Adornments cannot be made members of Groups. (Nor can they be linked, nor can they be selected, etc.) This is why you are getting that error. But we should improve that error message.

Almost always you will want to get the “obj.part.adornedObject” or the “obj.part.adornedPart”. In this case you want the latter, to get the Node that the context menu is adorning.

yeah it works. thanks