D3.js Tree Expand All and Collapse All
问题 I'm building a Tree using D3.js and what I am trying to do is add two buttons, Expand All and Collapse All to the top of the page like this. When I click "Expand All", all the nodes should expand. And when I click "Collapse All", all the nodes should collapse to the root element. Here's my current code http://bl.ocks.org/anonymous/ab8d7f85cca6f745a107 But the problem is, it isn't working. Can somebody suggest how to make it work? 回答1: Try this code. Here is the working JsFiddle. function