I want to introduce a complete hierarchy of elements available through the RESTful API.
To do this, I would like to use the D3 tree layout to load and draw nodes. This API can return all elements of a given type. However, the children of these elements are accessed via the reference URL, rather than a nested array.
When setting up my tree in D3, I try to install a child accessor function that uses d3.json () to return all children for a given node using this URL. Here is my tree building function so far, where rootis the top level element with the attribute Children:
function buildTreeFor(root) {
var tree = d3.layout.tree();
tree.children(function(node) {
d3.json(node.Children._ref, function(data) {
return data;
});
});
var nodes = tree.nodes(root);
var links = tree.links(nodes);
}
, , . D3 , . Promise, ? - node ?
, . , AJAX?
!