我有一個菜單,使用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