我敢肯定有一种非常简单优雅的方法可以做到这一点,但我无法弄清楚。我有一些看起来像这样的输入数据:
[
{id: 1, name: "Peter"},
{id: 2, name: "Paul", manager: 1},
{id: 3, name: "Mary", manager: 1},
{id: 4, name: "John", manager: 2},
{id: 5, name: "Jane", manager: 2}
]
如果可能,我想使用 d3.js 嵌套运算符来获取要在层次结构布局中使用的结构。像这样:
[
{name: "Peter", children: [
{name:"Paul", children: [
{name:"John"},
{name:"Jane"}
]},
{name:"Mary"}
]
}
]