Angular ng-repeat with nested json objects?

后端 未结 5 2036
鱼传尺愫
鱼传尺愫 2020-12-30 09:49

I have a JSON object, represented as such:

 {
  \"orders\" : [
    {
      \"ordernum\" : \"PRAAA000000177800601\",
      \"buyer\" : \"Donna Heywood\"
              


        
5条回答
  •  生来不讨喜
    2020-12-30 10:42

    You can just create new array 'parcels' like in demo below:

    var app = angular.module('app', []);
    app.controller('homeCtrl', function($scope) {
      $scope.data = {
        "orders": [{
          "ordernum": "PRAAA000000177800601",
          "buyer": "Donna Heywood",
          "parcels": [{
            "upid": "UPID567890123456",
            "tpid": "TPID789456789485"
          }, {
            "upid": "UPID586905486090",
            "tpid": "TPID343454645455"
          }]
        }, {
          "ordernum": "ORAAA000000367567345",
          "buyer": "Melanie Daniels",
          "parcels": [{
            "upid": "UPID456547347776",
            "tpid": "TPID645896579688"
          }, {
            "upid": "UPID768577673366",
            "tpid": "TPID784574333345"
          }]
        }]
      };
    
      $scope.parcels = [];
      angular.forEach($scope.data.orders, function(order) {
        angular.forEach(order.parcels, function(parcel) {
          $scope.parcels.push(parcel)
        })
      })
    });
    
    
    • {{o.upid}}

提交回复
热议问题