angular.foreach语句用于嵌套sjon

时间:2016-12-02 06:10:33

标签: angularjs

根据Project“neo nimbus sundance”

需要servicezone_name的孩子
    [  
   {  
      "_id":"57d7caa4906217a9e630ecac",
      "project":"Neo",
      "att_epc_zone":[  
         {  
            "zone_release":"1",
            "servicezone_name":"test123",
            "ntc_name":"ntc1",
            "nodes":[  
               "1a32a00a-3335-4d80-ae9e-f398e0decb7c",
               "eb935acc-df0e-4b7a-a8dc-e50c8b230288"
            ]
         },
         {  
            "zone_release":"1",
            "servicezone_name":"teset23",
            "ntc_name":"ntc3",
            "nodes":[  
               "3869b489-8f2e-473e-82c4-cc20159fcd12",
               "5cef0e44-4955-49b8-b791-02ea6bfe3e6c"
            ]
         },
         {  
            "zone_release":"1",
            "servicezone_name":"test",
            "ntc_name":"ntc2",
            "nodes":[  
               "ce12be4d-8fb9-4a68-8296-87bdbe292d5e",
               "eb935acc-df0e-4b7a-a8dc-e50c8b230288"
            ]
         }
      ]
   },
   {  
      "_id":"57d7cad7906217a9e630ecad",
      "project":"Sundance",
      "att_epc_zone":[  
         {  
            "zone_release":"1",
            "servicezone_name":"sun1",
            "ntc_name":"ntc1",
            "nodes":[  
               "3869b489-8f2e-473e-82c4-cc20159fcd12",
               "5cef0e44-4955-49b8-b791-02ea6bfe3e6c"
            ]
         }
      ]
   },
   {  
      "_id":"57d7cadf906217a9e630ecae",
      "project":"Nimbus",
      "att_epc_zone":[  
         {  
            "zone_release":"1",
            "servicezone_name":"neoproject",
            "ntc_name":"ntc3",
            "nodes":[  
               "ce12be4d-8fb9-4a68-8296-87bdbe292d5e",
               "eb935acc-df0e-4b7a-a8dc-e50c8b230288"
            ]
         },
         {  
            "zone_release":"1",
            "servicezone_name":"nimb1",
            "ntc_name":"ntc1",
            "nodes":[  
               "ce12be4d-8fb9-4a68-8296-87bdbe292d5e",
               "c293f7a6-a9e1-4dda-aaf1-da2c053e81b1"
            ]
         }
      ]
   }
]

fiddler code:https://jsfiddle.net/h9945394143/p38qwsq4/

2 个答案:

答案 0 :(得分:0)

angular.forEach($scope.data, function(value, key) {
    if (value.project === "Nimbus") {
      angular.forEach(value, function(value2, key2) {
        if (key2 === "att_epc_zone") {
          angular.forEach(value2, function(value3, key3) {
            alert(value3.servicezone_name);

          })
        }    
      })
    }

<强> DEMO

答案 1 :(得分:-1)

希望以下是您的要求,请通过运行代码段进行检查

<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <div ng-repeat="x in name"><b>{{x.project}}</b>
    <div  ng-repeat="y in x.att_epc_zone">{{y.servicezone_name}}</div>
    </div>
    <script>
     var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name =    [  
   {  
      "_id":"57d7caa4906217a9e630ecac",
      "project":"Neo",
      "att_epc_zone":[  
         {  
            "zone_release":"1",
            "servicezone_name":"test123",
            "ntc_name":"ntc1",
            "nodes":[  
               "1a32a00a-3335-4d80-ae9e-f398e0decb7c",
               "eb935acc-df0e-4b7a-a8dc-e50c8b230288"
            ]
         },
         {  
            "zone_release":"1",
            "servicezone_name":"teset23",
            "ntc_name":"ntc3",
            "nodes":[  
               "3869b489-8f2e-473e-82c4-cc20159fcd12",
               "5cef0e44-4955-49b8-b791-02ea6bfe3e6c"
            ]
         },
         {  
            "zone_release":"1",
            "servicezone_name":"test",
            "ntc_name":"ntc2",
            "nodes":[  
               "ce12be4d-8fb9-4a68-8296-87bdbe292d5e",
               "eb935acc-df0e-4b7a-a8dc-e50c8b230288"
            ]
         }
      ]
   },
   {  
      "_id":"57d7cad7906217a9e630ecad",
      "project":"Sundance",
      "att_epc_zone":[  
         {  
            "zone_release":"1",
            "servicezone_name":"sun1",
            "ntc_name":"ntc1",
            "nodes":[  
               "3869b489-8f2e-473e-82c4-cc20159fcd12",
               "5cef0e44-4955-49b8-b791-02ea6bfe3e6c"
            ]
         }
      ]
   },
   {  
      "_id":"57d7cadf906217a9e630ecae",
      "project":"Nimbus",
      "att_epc_zone":[  
         {  
            "zone_release":"1",
            "servicezone_name":"neoproject",
            "ntc_name":"ntc3",
            "nodes":[  
               "ce12be4d-8fb9-4a68-8296-87bdbe292d5e",
               "eb935acc-df0e-4b7a-a8dc-e50c8b230288"
            ]
         },
         {  
            "zone_release":"1",
            "servicezone_name":"nimb1",
            "ntc_name":"ntc1",
            "nodes":[  
               "ce12be4d-8fb9-4a68-8296-87bdbe292d5e",
               "c293f7a6-a9e1-4dda-aaf1-da2c053e81b1"
            ]
         }
      ]
   }
];
});

      
    </script>
  </body>

</html>