我现在正在创建一个使用D3.js树布局的Org图。组织结构图将由登录用户打开,要求显示默认打开给用户节点的组织结构图。
例如,如果登录用户是'n',那么组织结构图是:
j m
/ /
b - e - k
/
a - d - l - n
\
c- f - h
\
i用户将看到:
a - d - l - n因此,问题语句是将Org图表扩展到节点id/name是登录用户的特定节点。
欢迎任何帮助。
发布于 2016-05-04 12:05:12
首先,在每个数据对象中设置父对象:
function collapse(d) {
if (d.children) {
d._children = d.children;
//set the parent object in all the children
d._children.forEach(function(d1){d1.parent = d; collapse(d1);});
d.children = null;
}
}编写一个find函数,该函数查找节点并打开其所有父节点。
function find(d, name) {
if (d.name == name){
while(d.parent){
d = d.parent;
click(d);//if found open its parent
}
return;
}
//recursively call find function on its children
if (d.children) {
d.children.forEach(function(d){find(d, name)});
} else if(d._children){
d._children.forEach(function(d){find(d, name)});
}
}现在使用您希望看到的节点调用find函数。
var name = "layout";//example open till you find the node layout
find (root, name)工作代码here
https://stackoverflow.com/questions/37025838
复制相似问题