假设我有一个 json 如下:-
{
"name":"WorkBook",
"type":"xs:string",
"complexType": {
"name":"EmpID",
"type":"xs:string",
"complexType": {
"name":"Salary",
"type":"xs:string",
"complexType":null
}
}
}
我从 Spring Controller
生成此 json,它消耗 xsd
。 json 被传递到我的 angularJS Controller 。
“complexType”可以是 n 层深。
我的要求是在AngularJS/jsp中解析这个json
并为其创建一个类似层次树的结构
,有点像http://www.jstree.com/docs/html/ 。
(不可折叠且更简单即可)
有什么建议吗? (使用 ng-repeat 或其他东西,假设我有一个名为“xsdContents”的变量中的 json。
如果我需要向 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
无论如何,谢谢:)
关于javascript - 在 Angular 中解析 n 级深度 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29820658/