繁体   English   中英

angular.js:13920错误:[ngRepeat:dupes]在转发器中重复

[英]angular.js:13920 Error: [ngRepeat:dupes] Duplicates in a repeater

尝试在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

您的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。 尝试使用正确的数据并测试它是否正常工作。

<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按值ng-repeat跟踪。 track by $index添加track by $index将跟踪对象的位置。

做这个,

ng-repeat="log in searhController.orderlogs.results track by $index">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM