[英]Parse n level deep JSON in Angular
假設我有一個JSON,如下所示:-
{
"name":"WorkBook",
"type":"xs:string",
"complexType": {
"name":"EmpID",
"type":"xs:string",
"complexType": {
"name":"Salary",
"type":"xs:string",
"complexType":null
}
}
}
我正在從使用xsd
的Spring controller
生成此json。 json傳遞給我的angularJS
控制器。 “ complexType”可以是n級深的。
我的要求是parse this json in AngularJS/jsp
並為其創建hierarchial tree like structure
的hierarchial tree like structure
,有點像http://www.jstree.com/docs/html/ 。 (不可折疊且更簡單)
有什么建議怎么做嗎? (使用ng-repeat或其他方法,假設我將json放在名為“ xsdContents”的變量中。
如果這一切我都需要向json添加額外的參數,例如級別號或其他內容,那也是可能的。
經過研究后發現:
<script type="text/ng-template" id="categoryTree">
{{ category.title }}
<ul ng-if="category.categories">
<li ng-repeat="category in category.categories" ng-include="'categoryTree'">
</li>
</ul>
</script>
http://jsfiddle.net/benfosterdev/NP7P5/
資源:
http://benfoster.io/blog/angularjs-recursive-templates
不管怎么說,還是要謝謝你 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.