Update all Nodes

After reading GoJS Collections -- Northwoods Software I tried to set multiple nodes at sequentially by looping over them. However I keep getting an error " Is that really your intent?". What am I doing wrong?

if (node instanceof go.Node && node.data.isGroup) {
for (var it = myDiagram.nodes; it.next(); ) {
var n = it.value; // n is now a Node or a Group
if (n.data.type === “link_item”) {
myDiagram.model.setDataProperty(n, ‘status’, ‘deleted’);
}
}
console.log(myDiagram.model.toJson())
}

The Node class, Node | GoJS API, does not define a “status” property.

You probably want to call setDataProperty(n.data, 'status', 'deleted')

Thank you!

Where can i find more information about e.subject?

I am trying to access the data from e.subject, but its not working. I tried e.subject.part but I get undefined. I am trying to edit my code so it will allow deletes of links.

“SelectionDeleting”: function(e){
console.log(e.subject.part)
e.cancel = true;
myDiagram.startTransaction(‘change status’);
var data, arr = [], i = 0;
myDiagram.selection.each(function(node) {
if (node instanceof go.Node) {
data = node.data;
myDiagram.model.setDataProperty(data, ‘status’, ‘deleted’);
console.log(myDiagram.selection.first().part.data)
}
if (data.isGroup) {
for (var it = myDiagram.nodes; it.next(); ) {
var n = it.value; // n is now a Node or a Group
if (n.data.type === “link_item” && n.data.group === data.key ) {
myDiagram.model.setDataProperty(n.data, ‘status’, ‘deleted’);
console.log(n.data)
}
}
}

                    });
                   myDiagram.commitTransaction('change status');
              }

also SelectionDeleting is running while I create a group. Any reasons why?

The meanings of the arguments to a DiagramEvent listener is provided at DiagramEvent | GoJS API, for each named DiagramEvent.

The “SelectionDeleting” DiagramEvent is raised by CommandHandler.deleteSelection. Look up the stack to see why it is called.

I know it is invoked by delete key on keyboard. It works. However I am trying to access data of the node or link i am deleting. when i console.log(e.subject.part) it gives me undefined. I followed the examples on the forum and the DiagramEvent | GoJS API, and its not working.

Here is the documentation for that named DiagramEvent:

“SelectionDeleting”, the user is about to delete selected Parts by CommandHandler.deleteSelection; you can cancel the deletion by setting DiagramEvent.cancel to true; the DiagramEvent.subject is the Diagram.selection collection of Parts to be deleted, do not make any changes to the selection or the diagram.

Note the part that I italicized: DiagramEvent.subject is the Diagram.selection collection.

awesome thank you!