尝试在html
中阅读以下json和映射时出现以下错误JS:
searhController.orderlogs.results = JSON.stringify(response.data);
角:
<tr ng-hide="searhController.searching" ng-repeat="log in searhController.orderlogs.results">
<td>{{log.idTransaction}}</td>
<!-- <td>{{log.amount}}</td>
<td>{{log.clientName}}</td>
<td>{{log.created}}</td>
<td>{{log.currency}}</td>
<td>{{log.discountedAmount}}</td>
<td>{{log.lastUpdate}}</td>
<td>{{log.orderId}}</td> -->
</tr>
JSON:
[{"idTransaction":2081101,"amount":34990.0,"clientName":"Payment hub","created":"ene 12, 2015","currency":"CLP","discountedAmount":34990.0,"lastUpdate":"ene 12, 2015","orderId":"1421094905114","productDescription":"total: 1 item(s)","fop":{"nameFop":"CAT_FAKE"},"application":{"idApplication":10001,"nameApplication":"TEST APPLICATION"},"transactionStatus":{"nameTransactionStatus":"Waiting for reply"},"transactionByFop":{"settled_amount":0.0,"installments_amount":0.0,"installments_number":0}}]
错误:
angular.js:13920 Error: [ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: log in searhController.orderlogs.results, Duplicate key: string:a, Duplicate value: a
答案 0 :(得分:2)
您的JSON无效,您应该正确格式化它,因为它不是那么小 - 单行是非常糟糕的。
这是有效的:
{
"transaction":{
"idTransaction":2081101,
"amount":34990.0,
"clientName":"Payment hub",
"created":"ene 12, 2015",
"currency":"CLP",
"discountedAmount":34990.0,
"lastUpdate":"ene 12, 2015",
"orderId":"1421094905114",
"productDescription":"total: 1 item(s)",
"fop":{
"nameFop":"CAT_FAKE"
},
"application":"",
"idApplication":10001,
"nameApplication":"TEST APPLICATION"
},
"transactionStatus":{
"nameTransactionStatus":"Waiting for reply"
},
"transactionByFop":"",
"settled_amount":0.0,
"installments_amount":0.0,
"installments_number":0
}
我做了什么?
你有两个空的属性,没有填充任何数据并且像JSON一样摧毁你:
[INVALID] "attr1" : "attr2" : "valueOfAttr2",
[VALID] "attr1" : "", "attr2":"valueOfAttr2"
你有多个Root元素,因此它不是有效的JSON。 尝试使用正确的数据并测试它是否正常工作。
答案 1 :(得分:1)
<tr ng-hide="searhController.searching" ng-repeat="log in searhController.orderlogs.results track by $index">
<td>{{log.idTransaction}}</td>
<!-- <td>{{log.amount}}</td>
<td>{{log.clientName}}</td>
<td>{{log.created}}</td>
<td>{{log.currency}}</td>
<td>{{log.discountedAmount}}</td>
<td>{{log.lastUpdate}}</td>
<td>{{log.orderId}}</td> -->
</tr>
只需将track by $index
添加到ng-repeat
的末尾即可。现在,集合中的两个对象是相等的,默认情况下ng-repeat
按值跟踪。添加track by $index
将根据对象的位置进行跟踪。
答案 2 :(得分:0)
这样做,
ng-repeat="log in searhController.orderlogs.results track by $index">