【发布时间】:2016-06-14 11:27:36
【问题描述】:
我想在 Angular2 中将 JSON 树转换为无序列表。我知道 Angular1 中的递归指令解决方案,我很确定 Angular2 中的解决方案也将是递归的。
[
{name:"parent1", subnodes:[]},
{name:"parent2",
subnodes:[
{name:"parent2_child1", subnodes:[]}
],
{name:"parent3",
subnodes:[
{name:"parent3_child1",
subnodes:[
{name:"parent3_child1_child1", subnodes:[]}
]
}
]
}
]
到这个无序列表
<ul>
<li>parent1</li>
<li>parent2
<ul>
<li>parent2_child1</li>
</ul>
</li>
<li>parent3
<ul>
<li>parent3_child1
<ul>
<li>parent3_child1_child1</li>
</ul>
</li>
</ul>
</li>
</ul>
使用 Angular2 和 ngFor。有人有想法吗?
【问题讨论】:
-
stackoverflow.com/questions/35647365/… 展示了如何迭代 JSON。我猜你需要一个包装
ngFor的组件才能递归使用它。 -
PrimeNG 中有一个树组件可以检查,它在内部使用另一个名为 p:treeNode 的组件来执行递归。 primefaces.org/primeng/#/tree
标签: json tree html-lists angular