Change category of a node

Hi , i have a question

In the flowchart example http://gojs.net/latest/samples/flowchart.html , i tried to implement a function that enable the user to change the category of a specific node by the context menu and i did like this:

//create a context menu

$$(“ContextMenuButton”,
$$(go.TextBlock, “change type”),
{ click: function(e, obj) { ChangeType(e,obj); } },

//in function ChangeType

myDiagram.startTransaction(“Change Type”);
<span =“apple-tab-span”=“” style=“white-space:pre”> var holdNode = obj.part.adornedPart;
<span =“apple-tab-span”=“” style=“white-space:pre”> if (holdNode!=undefined && holdNode!=null)
<span =“apple-tab-span”=“” style=“white-space:pre”> {
<span =“apple-tab-span”=“” style=“white-space:pre”>
<span =“apple-tab-span”=“” style=“white-space:pre”> holdNode.data.category = “end”

<span =“apple-tab-span”=“” style=“white-space:pre”>
<span =“apple-tab-span”=“” style=“white-space:pre”> }
myDiagram.commitTransaction(“Change Type”);

this doesn’t work so i try to modify in the NodeDataArray

for (var i=0; i<=myDiagram.model.nodeDataArray.length-1;i++)
<span =“apple-tab-span”=“” style=“white-space:pre”> {
<span =“apple-tab-span”=“” style=“white-space:pre”> if (myDiagram.model.nodeDataArray.key==holdNode.key)
<span =“apple-tab-span”=“” style=“white-space:pre”> {
<span =“apple-tab-span”=“” style=“white-space:pre”> myDiagram.model.nodeDataArray.category = “end”;
<span =“apple-tab-span”=“” style=“white-space:pre”>
<span =“apple-tab-span”=“” style=“white-space:pre”>
<span =“apple-tab-span”=“” style=“white-space:pre”> }
<span =“apple-tab-span”=“” style=“white-space:pre”> }


this doesn’t work either. Is there anyway i can do this?


Thanks

In your second try, you are just changing the property of the Array holding your model’s node data, which will have no effect.

Your first try is basically right. However, whenever someone modifies a JavaScript property, there is no notification, so GoJS cannot know that the value changed. We did not want to require everyone to implement property setters that notify about property value changes. So you need to call Model.setDataProperty for regular properties and the appropriate Model method for structural changes to models. In this case, you should call model.setCategoryForNodeData. Please read about Data Binding.

Thanks… it works :)