如何使用ng-repeat或angular.forEach访问嵌套的json数据

时间:2014-10-28 11:10:03

标签: angularjs angularjs-ng-repeat

我有以下json文件。我无法动态获取数据。请帮我解决这个问题。 我的要求是我需要根据子模块查看url值,即; sname || ID。如果我正在访问sname作为chapter1我需要获得所有的视频 - >该子模块的url值。



[
   {
      "name":"Introduction - About The PMP Credential",
      "sub1":[
         {
            "sname":"Introduction to PMP",
            "id":"1",
            "vid":[
               {
                  "url":"www.abcd.co"
               },
               {
                  "url":"www.xyz.com"
               },
               {
                  "url":"www.xyz.com"
               }
            ]
         },
         {
            "sname":"Chapter1",
            "id":"2",
            "vid":[
               {
                  "url":"www.abcd.co"
               },
               {
                  "url":"www.xyz.com"
               }
            ]
         },
         {
            "sname":"Justification",
            "id":"3",
            "vid":[
               {
                  "url":"www.abcd.co"
               },
               {
                  "url":"www.xyz.com"
               }
            ]
         }
      ]
   },
   {
      "name":"Project Management Framework",
      "sub1":[
         {
            "sname":"Project Seminar",
            "id":"4",
            "vid":[
               {
                  "url":"www.abcd.co"
               },
               {
                  "url":"www.xyz.com"
               }
            ]
         },
         {
            "sname":"Introduction to Communication Management",
            "id":"5",
            "vid":[
               {
                  "url":"www.abcd.co"
               },
               {
                  "url":"www.xyz.com"
               }
            ]
         },
         {
            "sname":"Final Communication Management",
            "id":"6",
            "vid":[
               {
                  "url":"www.abcd.co"
               },
               {
                  "url":"www.xyz.com"
               }
            ]
         },
         {
            "sname":"Modules",
            "id":"7",
            "vid":[
               {
                  "url":"www.abcd.co"
               },
               {
                  "url":"www.xyz.com"
               }
            ]
         }
      ]
   },
   {
      "name":"Cost Management",
      "sub1":[
         {
            "sname":"Introduction to Cost Management",
            "id":"8",
            "vid":[
               {
                  "url":"www.abcd.co"
               },
               {
                  "url":"www.xyz.com"
               }
            ]
         },
         {
            "sname":"Cost Management Introduction",
            "id":"9",
            "vid":[
               {
                  "url":"www.abcd.co"
               },
               {
                  "url":"www.xyz.com"
               }
            ]
         }
      ]
   }
]




1 个答案:

答案 0 :(得分:0)

    <div ng-repeat="item_nm in test">{{item_nm.name}}
        <div ng-repeat="sub1_dt in item_nm.sub1">
            {{sub1_dt.sname}}
            <div ng-repeat="vid in sub1_dt.vid">
                {{vid.url}}
            </div> 
      </div> 
    </div>

This will display name and corresponding sname and its url.