【问题标题】:I'm developing an App using Ionic Angular and PHP for the backend. I am returning this JSON string from PHP and I'm receiving it as it is in Angular我正在开发一个使用 Ionic Angular 和 PHP 作为后端的应用程序。我正在从 PHP 返回这个 JSON 字符串,并且我正在接收它,因为它在 Angular 中
【发布时间】:2017-01-05 09:43:54
【问题描述】:

我正在开发一个使用 Ionic Angular 和 PHP 作为后端的应用程序。 我正在从 PHP 返回这个 JSON 字符串,并且我正在接收它,因为它在 Angular 中

[
{
    "HistoryId":"440",
    "TotalPrice":"24",
    "aa":[{"orderid":"630","foodId":"1","quantity":"1","name":"Mixed Starter (Minimum For Two)","price":"9"},         {"orderid":"641","foodId":"3","quantity":"1","name":"Sesame chicken on toast","price":"5"},
          {"orderid":"662","foodId":"2","quantity":"2","name":"Sesame prawn on toast","price":"5"}]
},
{
    "HistoryId":"451",
    "TotalPrice":"24",
    "aa":[{"orderid":"650","foodId":"1","quantity":"1","name":"Mixed Starter (Minimum For Two) ","price":"9"},        {"orderid":"671","foodId":"3","quantity":"1","name":"Sesame chicken on toast","price":"5"},
          {"orderid":"682","foodId":"2","quantity":"2","name":"Sesame prawn on toast","price":"5"}]
}
]

但是当我尝试展示它时 我收到此错误:

Error: [ngRepeat:dupes] Duplicates in
a repeater are not allowed. Use 'track by' expression 
to specify unique keys. Repeater: oh in orderHistory,
Duplicate key: string:", Duplicate value: "

【问题讨论】:

  • 你能告诉我们你的迭代代码吗?
  • @Hamooz 你能贴出你的角码吗?
  • {{oh.HistoryId}}

    价格:{ {oh.TotalPrice }}

    @vineet
  • $scope.orderHistory= angular.toJson(response.data); @ashu jha

标签: php angularjs json ionic-framework


【解决方案1】:

使用这个

<ion-item ng-repeat="oh in orderHistory track by $index" > <h2>{{oh.HistoryId}} </h2> <h3 style="color:green">Price: {{oh.TotalPrice }}</h3> <ion-card> <ion-item ng-repeat="o in oh.aa ">

AngularJS 不允许在 ng-repeat 指令中重复

【讨论】:

  • 当我将它与 $index 一起使用时,它显示了很多迭代但没有价值只有空的 ionCards @vineet
  • 它们没有重复,这就是我放 JSON 结果的原因
  • 你试过这个&lt;ion-item ng-repeat="o in oh.aa track by o.orderid"&gt; 吗?
  • 伟大的@Hamooz。但是很难猜测你是否已经反序列化了 json。 :)
猜你喜欢
  • 1970-01-01
  • 2020-06-28
  • 2015-01-10
  • 1970-01-01
  • 2020-09-09
  • 1970-01-01
  • 1970-01-01
  • 2015-09-25
  • 1970-01-01
相关资源
最近更新 更多