var sketchNode = myDiagram.findNodesByExample({ key: "sketch" });
console.log("sketchNode.count:"+sketchNode.count);//if the sketchNode.count is 2.
var it = sketchNode.iterator;
while (it.next()) {
console.log(it.key + "--- " + it.value);
}
myDiagram_${diagramId}_${diagramType}.startTransaction("removesketchNodes");
myDiagram_${diagramId}_${diagramType}.model.removeNodeDataCollection(sketchNode);//removing is invalid ,why???
myDiagram_${diagramId}_${diagramType}.commitTransaction("removesketchNodes");
the results of console.log();
First, I want to find the nodes that it’s key is “sketch” on the myDiagram.
Then,I want to remove the nodes on the myDiagram.
What Would l Do?
Q2:
var nodeLength = myDiagram.model.nodeDataArray.length;
console.log("nodeLength:"+nodeLength);
for(var k=0;k<nodeLength;k++){
var sketchNode = myDiagram.model.nodeDataArray[k].key;
if(sketchNode=="sketch"){
var nodedata = myDiagram.model.nodeDataArray[k];
myDiagram.startTransaction("removesketchNodes");
myDiagram.model.removeNodeData(nodedata);
myDiagram.commitTransaction("removesketchNodes");
}
}
When I delete it one by one, and make a mistake, what is the reason?
The problem with your code is that Model.removeNodeDataCollection takes an Array or a go.Iterable of model data objects. But Diagram.findNodesByExample returns an Iterator of Nodes, not node data.
If “key” is actually the value of Model.nodeKeyProperty, then I do not see how you could find more than one node for that key. Maybe if you used a RegExp or if you were checking a different property.
As it is, assuming there can be only one such node:
Q1:I set the nodeKeyProperty is"nodeId";
Q2:I am modifying a collection (in this case an Array) while I am iterating over it. The behavior for that operation is not defined.I don’t know what is the right thing to do.