2016-08-04 103 views
1

我试图阅读以下JSON和映射在HTMLangular.js:13920错误:[ngRepeat:愚弄]在一个中继器重复

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

您发布的JSON无效......有几个错误。使用在线校验器或浏览器插件。你不应该串流你的JSON使用JSON.parse(response.data) – sascha10000

+0

好,但根据几个页面json是有效的 –

+0

比这些网页不好,或者你没有验证你发布的JSON。因为像这样的一行“transactionByFop”:“settled_amount”:0.0,100%无效。 我使用https://jsonformatter.curiousconcept.com/进行验证。 – sascha10000

回答

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 $indexng-repeat结束。现在你的收藏中的两个物品是相同的,并且ng-repeat默认跟踪值。添加track by $index将跟踪对象的位置。

+0

谢谢,我工作 –

+0

请投票正确的答案,并检查一个关闭作为正确的答案。 –

0

做到这一点,

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

谢谢,我工作 –

+0

@MarioAaronGonzalezSanchez你可以标记为答案 – Sajeetharan

+0

这将是很好的。对于我和用户在搜索时发现这个问题:)。 – sascha10000

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" 

,你不得不因此一个以上的根元素是不是有效的JSON。 尝试使用正确的数据并测试它是否正常工作。

+0

我工作是一个问题,应该添加索引,并设置结果, 谢谢 –

相关问题