简体   繁体   中英

Parse n level deep JSON in Angular

Supposingly I have a json as follows: -

{
    "name":"WorkBook",
    "type":"xs:string",
    "complexType": {
        "name":"EmpID",
        "type":"xs:string",
        "complexType": {
            "name":"Salary",
            "type":"xs:string",
            "complexType":null
        }
    }
}

I am producing this json from a Spring controller , which consumes a xsd . The json is passed on to my angularJS controller. The 'complexType' can be n-levels deep.

My requirement is to parse this json in AngularJS/jsp and create a hierarchial tree like structure for the same, somewhat like http://www.jstree.com/docs/html/ . (Non collapse-able and simpler would do)

Any suggestions how to go about it? (Using ng-repeat or something, assuming I have the json in a variable called 'xsdContents'.

If it all I need to add extra parameters to json, such as level number or something, that is also possible.

After a bit of a research, found this:

<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/

Source:

http://benfoster.io/blog/angularjs-recursive-templates

Thanks anyway :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM