2013-10-17 119 views

回答

2

在此示例中,节点折叠的方式是删除数据元素的.children成员,以便不绘制子节点。您可以静态执行此操作,以便将所有内容都折叠起来。代码看起来像这样。

function moveChildren(node) { 
    if(node.children) { 
     node.children.forEach(function(c) { moveChildren(c); }); 
     node._children = node.children; 
     node.children = null; 
    } 
} 
moveChildren(json); 

变形例here