现在,如果要扩展一个节点,我想折叠所有其他节点。例如在图中,如果analytics node
展开,则它应该崩溃data node
。我指的是D3.js可折叠树-扩展/折叠中间节点,但没有太大帮助。
我在Przemek提示的帮助下获得了解决方案。现在它可以完美运行了。:)
function click(d) {
var index;
for(var i=0;i<d.parent.children.length;i++){//length of current label
if(d.parent.children[i].name===d.name)
index = i;
};
for(var i=0;i<d.parent.children.length;i++){
if(typeof d.parent.children[i].children!=="undefined" && i!=index){//if child is expnd then make null
d.parent.children[i]._children=d.parent.children[i].children;
d.parent.children[i].children= null;
}
}
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
update(d);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句