[英]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.