我有一个菜单,使用ul
和li
。我想通过Angular和JSON对象来显示它。如何通过Angular Js显示n层嵌套json对象?
我尝试做ng-repeat
但我的问题是,如果我的对象有20层嵌套对象或在另一方面它有n层嵌套的孩子如何显示它?
代码HTML
<ul>
<li ng-repeat="item in model">
{{item.text}}
</li>
</ul>
和我的JSON对象是:
var model = [
{ text: "one", link: "#" },
{ text: "tow", link: "#" },
{
text: "three",
link: "#",
children: [
{ text: "four", link: "#" },
{ text: "five", link: "#", children: [{text:"nine", link:"#"}] },
{ text: "six", link: "#" }
]
}];
$scope.model = model;
可能的重复http://stackoverflow.com/questions/34737227/using-ng-repeat-how-to-retrieve-data-from-nested-json-object?rq=1 –
@steady_daddy你的答案是不正确的,因为它仅支持2层 – Motion