Angular.js ng-repeat迭代通过远程JSON数组问题

时间:2015-08-25 19:31:36

标签: javascript html arrays angularjs angularjs-ng-repeat

搜索后,我看不出我做错了什么。基本上我的JSON返回一个看起来像这样的数据数组:

  "Alerts": [
    {
      "id": "164579",
      "date": "2013-05-17T16:46:58",
      "type": "ClaimReceivedNotification",
      "descr": "Your claim submission has been received and is pending review by our claims department.",
      "isRead": false,
      "denialId": "",
      "denialType": "",
      "dueDate": "0001-01-01T00:00:00",
      "amount": 0
    },
.......and so on......

所以我要做的就是用这个html中显示的日期和描述(descr)来解决这个问题:

                    <div>
                        <span ng-repeat="date in ppt.Alerts"> {{ ppt.Alerts[0].date }} </span>
                        <!-- <span> {{ ppt.Alerts[0].descr }} </span> -->
                    </div>

它确实显示,但只是数组中的第一个条目。如果我取出索引“[0]”并尝试替换为:

<span ng-repeat="date in ppt.Alerts[]"> {{ ppt.Alerts.date }} </span>

它什么也没显示。在使用它来使它迭代遍历数组中的每个实例并返回特定值时,我在哪里出错?

非常感谢!

1 个答案:

答案 0 :(得分:3)

当您重复date并且您已经说过循环的每个元素都称为date时,您可以轻松地使用<span ng-repeat="date in ppt.Alerts"> {{date.date}} </span> 来显示每个警报的日期。

<强>标记

<project>
  <groupId>com.mycompany</groupId>
  <artifactId>my-project</artifactId>
  <version>1.0</version>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.assertj</groupId>
      <artifactId>assertj-core</artifactId>
      <!-- use 3.1.0 for Java 8 projects -->
      <version>2.1.0</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>