Deleting node from model

Hi Walter,

To create a new node i have used below code
vm.myDiagram.startTransaction(“add node and link”);
vm.myDiagram.model.addNodeData({ key: vm.myDiagram.model.nodeDataArray[0].key+vm.i , name:vm.draggedNodeName , color: “#F0F0F0” , location: “100 -50”}); // this makes sure the key is unique
vm.myDiagram.model.addLinkData({ from: vm.myDiagram.model.nodeDataArray[0].key, to: vm.myDiagram.model.nodeDataArray[0].key+vm.i });
vm.myDiagram.commitTransaction(“add node and link”);

which works fine now i need to delete node i have written like below but it did;nt work

vm.myDiagram.startTransaction(“remove node data”);
vm.myDiagram.model.removeNodeData({ key: vm.myDiagram.model.nodeDataArray[index+1].key , name:reportname , color: “#F0F0F0” , location: “100 -50”}); // this makes sure the key is unique
vm.myDiagram.commitTransaction(“remove node data”);

Please help

Models use equality by reference, so you are asking to remove a new node data object, which cannot already exist in the model. Call Diagram.findNodesByExample if you really want to do that.

But in this case you don’t.

var node = myDiagram.findNodeForKey(...key...);
if (node !== null) {
  myDiagram.startTransaction();
  myDiagram.remove(node);
  myDiagram.commitTransaction("deleted node");
}

thanks walter.
I have a few qns :
1)On selecting node or on canvas hover i see a blue border displayed i need to remove that is there any event to do that.
2)I need to customize context menu and apply some css according to my need can we do that.
3) the links created can be dragged with mouse drag i need to stop that once the link created it should not be draggable.

Pls help

These seem to be different topics that each deserve their own forum topic. It would also help a lot if you provided screenshots or sketches for each.

  1. For selection, please read GoJS Selection -- Northwoods Software.
    For hover, I don’t know what you are seeing.

  2. For context menus, please read GoJS Context Menus -- Northwoods Software and GoJS HTML Interaction -- Northwoods Software

  3. Could you provide more details for what you have done? What properties have you set on your Links?

A post was split to a new topic: How to limit dragging