Deleting a Node and its Link/s

Hi ,

I am trying to delete a node and all it link from our workflow diagram, using the below code.

var fromNode = adorn.adornedPart;
<span =“Apple-tab-span” style=“white-space:pre”> var fromData = fromNode.data;
<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”> var model = diagram.model;
<span =“Apple-tab-span” style=“white-space:pre”>

<span =“Apple-tab-span” style=“white-space:pre”> model.removeNodeData(fromData);
<span =“Apple-tab-span” style=“white-space:pre”> <span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> var it = fromNode.linksConnected;
<span =“Apple-tab-span” style=“white-space:pre”> while (it.next()) {<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> var item = it.value;<span =“Apple-tab-span” style=“white-space:pre”>
<span =“Apple-tab-span” style=“white-space:pre”> model.removeLinkData(item);
<span =“Apple-tab-span” style=“white-space:pre”> }

The node deletion is successful but the link deletion is not working. Is there any thing I am missing or there is a different way to achieve this.

Thanks in advance for the help.

Nitin

Presumably your GraphLinksModel does not contain Link elements as its link data in the GraphLinksModel.linkDataArray. Instead it should have regular JavaScript objects, to which the Link parts are data bound.

So you probably just need to say:
model.removeLinkData(item.data);

Note that it might be easier to just call diagram.commandHandler.deleteSelection(), if the Node that you want to delete is the only selected Part. The command also raises the appropriate events, which you do not show in your code above.

Alternatively you can call Diagram.remove(node) to get the same effect as your code above.

Thanks Walter this works like a charm.

One more thing is I am a very new developer for this library and all these questions are very naive. Is there any tutorial which I can refer to get all this info upfront.

Thanks once once again.

Thanks,
Nitin

The GoJS Introduction: gojs.net/latest/intro

BTW, we’re about to release version 1.2. You can try the latest beta at GoJS - Build Interactive Diagrams for the Web.

A post was split to a new topic: Deleting node from model

A post was merged into an existing topic: Deleting node from model