Delete child nodes on click of button present on parent node


I have 2 buttons present on a node :
i) Expand - which makes a REST call, and gets the child nodes for that particular node achieved using:


ii) Collapse - Which will delete the set of nodes we got in step (i).

In step 2 i am not able to delete the set of nodes shown in step 1.
How can we achieve the same ?
My diagram looks something like this :

I suppose the most general solution is to mark all of those new nodes with a property to say that they were added as a result of that asynchronous addition to the model for that node, which I assume is referred to by parentid in your code.

Then you can search the model for all such nodes and delete them.

Hi Walter,
That helped.