本文介绍了如何从所有在d3js中折叠的节点开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从此示例开始我想要一个包含所有节点的树已折叠,因此初始图只应包含一个节点(根)。
Starting from this example http://bl.ocks.org/1062288 I would like to have a tree with all the nodes collapsed, so the initial graph should contain only one node (the root).
推荐答案
选项1:修改JSON
Option 1: Modify the JSON
修改JSON文件 readme.json
code> _children 而不是儿童
。
Modify the JSON file, readme.json
, to use _children
instead of children
.
:编辑JavaScript
编辑javascript以切换 _children
和 children
属性。这可以这样做
Edit the javascript to switch the _children
and children
attributes for every node. This could be done like so
var nodes = flatten(root);
nodes.forEach(function(d) {
d._children = d.children;
d.children = null;
});
这里是第二个选项。
这篇关于如何从所有在d3js中折叠的节点开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!