javascript - How do I delete a D3 tree node using code? -


Let me know it

I would like to delete a node (and its link)

In my last attempt:.

I saved dome in dome as d.id $ ('# inpSelidTAUsers') Val () then tried this code ...

. Filter (function (d, i) {if (d.target.id == $ ('# inpSelidTAUsers')) (true) return true to 'svgGroup.selectAll' ('path.link') Second False return;}) Remove (); . SvgGroup.selectAll ('g.node') is the data (node) .filter (function (d, i) {if (d.id == $ ('# inpSelidTAUsers'), val ()) return true; any other unrealistic Returning;}). Delete ();

This code removes nodes and links on the screen. But if I call the Draw Is Node RE-APPEARS Please let me know how can I remove the node, so it remains :)

G.node gives you the selection element, and even though you have removed it from the scene, it seems that you reboot it, unhinded because you are not changing the underlying data When you reboot it, you will get the same thing for the first time.

If you run the node you need to change the dataset. Your data is in this object:

  treedata = {'name': 'm', 'pOS': 'CEO', 'kids': [[' '' name ':' Mr. X '' POS ':' Sales Manager '}, {' Name ':' Mr. Y ',' POS ':' Architect '}, {' Name ':' Mr. Z ',' POS ':' Finance Assistant ' 'Children': [{'' name ':' Mr. U ',' POS ':' window cleaner '}]},]};  

To be able to remove such a function from the obvious way to a treeData object, perhaps to remove the children nodes:

  treeData. RemoveChild = function (idxToRemove) {var i, lane, result; Result = []; (I = 0, lane = this.children.length; i & lt; lane; i ++) {if (i == idxToRemove!) {Results.push (treeData.children [i]); }} This.children = Result; };  

Then you will call the indicator of the element that you want to delete:

  treeData.removeChild (2) // removes the final child  

Then stop the data and update the view.


Comments