为什么我的嵌套ng-repeat工作不正常

时间:2016-09-20 06:39:27

标签: angularjs arrays json angularjs-ng-repeat

我不太确定我的ng-repeat会发生什么,但这就是我所拥有的。

<div ng-controller="DeliveryController">
    <div ng-repeat="stop in Deliveries">
        <div >
            {{stop.stopId}}
        </div>
        <div ng-repeat="box in stop.Boxes">
            <div>
                {{box.orderNum}}
            </div>
        </div>
    </div>
</div>

唯一要返回的是第一个stop.stopId。我不太确定我的json是关闭还是发生了什么。任何想法都将不胜感激。

以下是我的api电话回复的内容。

          [
  {
    "stopsInfo": {
      "boxes": [
        {
          "boxID": 1,
          "orderNum": "1",
          "boxNum": "03600029145",
          "sts": "ORD",
          "lat": 41.33465,
          "lng": -40.5703457,
          "eventDt": "2016-09-20T00:39:05.323",
          "stopId": 1
        },
        {
          "boxID": 9,
          "orderNum": "2",
          "boxNum": "12345678901",
          "sts": "ORD",
          "lat": 41.33465,
          "lng": -40.5703457,
          "eventDt": "2016-09-20T00:39:07.85",
          "stopId": 1
        },
        {
          "boxID": 10,
          "orderNum": "3",
          "boxNum": "01600066060",
          "sts": "ORD",
          "lat": 41.33465,
          "lng": -40.5703457,
          "eventDt": "2016-09-20T00:39:09.607",
          "stopId": 1
        }
      ],
      "stopId": 1,
      "contactName": "Justin",
      "companyName": "Ignite LLC",
      "addr1": "123 Main",
      "addr2": "Suite 100",
      "city": "Katy",
      "state": "TX",
      "zip": "77449"
    },
    "signeeId": 1,
    "signee": "Justin",
    "signature": "asdasds",
    "stopId": 1
  },
  {
    "stopsInfo": {
      "boxes": [
        {
          "boxID": 12,
          "orderNum": "4",
          "boxNum": "12345678910",
          "sts": "ORD",
          "lat": 43.38928,
          "lng": -40.2342344,
          "eventDt": "2016-09-19T18:29:28.077",
          "stopId": 5
        },
        {
          "boxID": 14,
          "orderNum": "5",
          "boxNum": "123456",
          "sts": "ORD",
          "lat": 43.38928,
          "lng": -40.2342344,
          "eventDt": "2016-09-16T16:03:10.777",
          "stopId": 5
        }
      ],
      "stopId": 5,
      "contactName": "Paul",
      "companyName": "Ceremity",
      "addr1": "456 Moutain View",
      "addr2": "Suite 200",
      "city": "Katy",
      "state": "TX",
      "zip": "77449"
    },
    "signeeId": 8,
    "signee": "Paul",
    "signature": "asdasdsadsa",
    "stopId": 5
  },
  {
    "stopsInfo": {
      "boxes": [
        {
          "boxID": 15,
          "orderNum": "6",
          "boxNum": "63938200039",
          "sts": "ORD",
          "lat": 45.32312,
          "lng": -43.2345324,
          "eventDt": "2016-09-14T00:00:00",
          "stopId": 6
        }
      ],
      "stopId": 6,
      "contactName": "Vlad",
      "companyName": "Starbucks",
      "addr1": "789 Riveroak",
      "addr2": "Suite 300",
      "city": "Katy",
      "state": "TX",
      "zip": "77449"
    },
    "signeeId": 9,
    "signee": "Vlad",
    "signature": "asdasdasdasd",
    "stopId": 6
  }
]

1 个答案:

答案 0 :(得分:2)

boxes数组位于stopsInfo对象内。 将循环更改为:

<div ng-controller ="DeliveryController" >

    <div ng-repeat="stop in Deliveries">
        <div >
            {{stop.stopId}}
        </div>
        <div ng-repeat="box in stop.stopsInfo.boxes">
            <div>
                {{box.orderNum}}
            </div>
        </div>
    </div>
</div>

Plunker Sample here