2016-08-04 100 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

我工作是一個問題,應該添加索引,並設置結果, 謝謝 –

相關問題