本文介绍了如何从 d3js 中折叠的所有节点开始?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从这个例子开始 http://bl.ocks.org/1062288 我想要一棵树的所有节点都折叠了,所以初始图应该只包含一个节点(根).

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

修改 JSON 文件 readme.json,使用 _children 而不是 children.

Modify the JSON file, readme.json, to use _children instead of children.

选项 2:编辑 Javascript

编辑 javascript 以切换每个节点的 _childrenchildren 属性.可以这样做

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;
});

这是第二个选项的 JSFiddle.

这篇关于如何从 d3js 中折叠的所有节点开始?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:49
查看更多