D3树布局没有折叠

时间:2013-04-14 00:22:10

标签: javascript json d3.js

我之前曾问过类似的问题,但似乎我对我的问题不够准确 - 希望这是。

树布局的许多示例将其层次结构数据格式设置为:https://gist.github.com/tchaymore/1249394#file-math_map_compact-json

但是我想将json中的“children”节点更改为“children1”,例如

       var flare = {

"Name": "Example",
"children1": [


{
 "BName":"Ja",   
 "Email":"",
 "children1":[
 {

    "NickName":"NC",
    "id":2

 }
],

}
 ]};

当我更改了该节点的名称后,我使用了children函数:

 var tree = d3.layout.tree()
.size([height, width])
.children(function(d) { return d.children1; });

之后,我将所有“儿童”引用改为“children1”&等等。

但是,现在我遇到的问题是无法将树折叠回其父级。我试过用这个例子作为参考,但没有运气:http://blog.pixelingene.com/2011/07/building-a-tree-diagram-in-d3-js/

以下是我当前问题的一个示例:http://jsfiddle.net/mEyQW/1/

..我为之前的困惑道歉

1 个答案:

答案 0 :(得分:0)

我对collapse()函数和_children1没有真正的想法,但是如果删除它,那么一切正常:

jsFiddle:http://jsfiddle.net/chrisJamesC/mEyQW/2/

相关问题