我正在开发一个使用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: "
使用
<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指令中的重复项