Skip to content

Instantly share code, notes, and snippets.

@renemonroy
Forked from javedulu/d3treeAddDynamicChild.js
Created January 22, 2016 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renemonroy/c5fd89793592262d12f6 to your computer and use it in GitHub Desktop.
Save renemonroy/c5fd89793592262d12f6 to your computer and use it in GitHub Desktop.
Adding Dynamic content to d3.js tree on click of child node : http://bl.ocks.org/d3noob/8375092
function click(d) {
if (!d.children && !d._children)
{
d3.json("http://xxxx:2222/getChildNodes", function(error,response) {
response.children.forEach(function(child){
if (!tree.nodes(d)[0]._children){
tree.nodes(d)[0]._children = [];
}
child.x = d.x0;
child.y = d.y0;
tree.nodes(d)[0]._children.push(child);
});
if (d.children) {
d._children = d.children;
d.children = null;
}
else {
d.children = d._children;
d._children = null;
}
update(d);
});
}
if (d.children) {
d._children = d.children;
d.children = null;
}
else {
d.children = d._children;
d._children = null;
}
update(d);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment