javascript - 在 Angular 中解析 n 级深度 JSON

标签 javascript json angularjs jsp spring-mvc

假设我有一个 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/

相关文章:

javascript - 阻止了具有 origin "http://static.ak.facebook.com"的框架访问具有 origin 的框架

javascript - 使用 ui.grid 与 cellTemplate 共享 $scope

json - jqGrid - 分页无法正常工作

javascript - Google map 更改单选按钮选择上 JSON 覆盖的填充颜色

javascript - Angular Bootstrap : data-provide ="datepicker" not using format identifier

javascript - 用于构建 AngularJS 应用程序的正确 API 架构

javascript - 将 vsix 提取到 javascript 文件的实验扩展路径时出现问题

javascript - 在 chrome 中工作时 string.contains() 不存在

javascript - 从 dayClick 的后台事件中获取 Id 和 title

java - 为什么Gson会反序列化1为1.0?