2016-12-25 3 views
-1

habe ich eine json unterNested json Schleife in AngularJS

var returnObj = { 
     "subscriptions": [ 
    { 
     "subscriptionId": "ef94e4226e2b1a3c218ae5bd07273726", 
     "productId": "WBP", 
     "plans": [ 
     { 
      "planId": "WBP_INCL_UPDATES", 
      "attributes": [ 
      { 
       "vintage": "2016-10", 
       "url": "https://google.com", 
       "release": "0.0.0", 
       "expiredOn": "2016-12-23T07:33:18.093+0000" 
      }, 
      { 
       "vintage": "2016-11", 
       "url": "https://yahoo.com", 
       "release": "0.0.0", 
       "expiredOn": "2016-12-23T07:33:18.094+0000" 
      } 
      ] 
     } 
     ] 
    }, 
    { 
     "subscriptionId": "ee94e4226e2b1a3c218ae5bd07273726", 
     "productId": "POI", 
     "plans": [ 
     { 
      "planId": "POI_ARG", 
      "attributes": [] 
     } 
     ] 
    } 
    ] 
}; 
gegeben

ich es in AngularJS Tabellenformat Ausgabe angezeigt werden soll werden wie unten angegeben

Namen URL

WBP https://google.com

WBP https://yahoo.com

Antwort

0

Hoffnung t seine hilft Ihnen

var returnObj = { 
 
     "subscriptions": [ 
 
    { 
 
     "subscriptionId": "ef94e4226e2b1a3c218ae5bd07273726", 
 
     "productId": "WBP", 
 
     "plans": [ 
 
     { 
 
      "planId": "WBP_INCL_UPDATES", 
 
      "attributes": [ 
 
      { 
 
       "vintage": "2016-10", 
 
       "url": "https://google.com", 
 
       "release": "0.0.0", 
 
       "expiredOn": "2016-12-23T07:33:18.093+0000" 
 
      }, 
 
      { 
 
       "vintage": "2016-11", 
 
       "url": "https://yahoo.com", 
 
       "release": "0.0.0", 
 
       "expiredOn": "2016-12-23T07:33:18.094+0000" 
 
      } 
 
      ] 
 
     } 
 
     ] 
 
    }, 
 
    { 
 
     "subscriptionId": "ee94e4226e2b1a3c218ae5bd07273726", 
 
     "productId": "POI", 
 
     "plans": [ 
 
     { 
 
      "planId": "POI_ARG", 
 
      "attributes": [] 
 
     } 
 
     ] 
 
    } 
 
    ] 
 
}; 
 

 

 
var app = angular.module('myApp', []); 
 
app.controller('customersCtrl', function($scope, $http) { 
 
    $scope.rows = []; 
 
    returnObj.subscriptions.forEach(function(subscription){ 
 
    subscription.plans.forEach(function(plan){ 
 
     plan.attributes.forEach(function(attribute){ 
 
     $scope.rows.push({name: subscription.productId, url: attribute.url}); 
 
     }); 
 
    }); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="myApp" ng-controller="customersCtrl"> 
 

 
<table> 
 
    <tr><td>Name</td><td>URL</td></tr> 
 
    <tr ng-repeat="row in rows"> 
 
    <td>{{ row.name }}</td> 
 
    <td>{{ row.url }}</td> 
 
    </tr> 
 
</table> 
 

 
</div>