2014-09-23 59 views
1

這裏是我的html,NG-重複的錯誤: 「在一箇中繼器不允許重複」

<tr ng-repeat="val in attribute.format.values"> 

我得到,

[Duplicates in a repeater are not allowed. Use 'track by' expression to specify unique keys. Repeater: val in attribute.format.values, Duplicate key: object:07F, Duplicate value: {2}][1] 

這裏是我的JSON,

[{ 
    "name": "Auto", 
    "weight": "1", 
    "value": "1", 
    "count": 0, 
    "min": 0, 
    "max": 0, 
    "children": [], 
    "id": "06c9f57c-963f-4977-bca5-9226e971a8dc", 
    "visible": true, 
    "$$hashKey": "06V" 
}, { 
    "name": "On", 
    "weight": "1", 
    "value": "2", 
    "count": 0, 
    "min": 0, 
    "max": 0, 
    "children": [], 
    "id": "dc019b87-1da5-4f21-b91f-4ee35ec04eb8", 
    "visible": true, 
    "$$hashKey": "06W" 
}, { 
    "name": "Off", 
    "weight": "1", 
    "value": "4", 
    "count": 0, 
    "min": 0, 
    "max": 0, 
    "children": [], 
    "id": "daf8ef80-a2da-4e02-8960-791b8528905e", 
    "visible": true, 
    "$$hashKey": "06X" 
}, { 
    "name": "Redeye Reduction", 
    "weight": "1", 
    "value": "5", 
    "count": 0, 
    "min": 0, 
    "max": 0, 
    "children": [], 
    "id": "87ccb4ee-39cd-4bd0-9817-7e477af6d5b0", 
    "visible": true, 
    "$$hashKey": "06Y" 
}, { 
    "name": "Slow Sync", 
    "weight": "1", 
    "value": "6", 
    "count": 0, 
    "min": 0, 
    "max": 0, 
    "children": [], 
    "id": "e0b14c8b-af4b-4ab8-a533-32ac4829613f", 
    "visible": true, 
    "$$hashKey": "06Z" 
}, { 
    "name": "High Speed Sync", 
    "weight": "1", 
    "value": "7", 
    "count": 0, 
    "min": 0, 
    "max": 0, 
    "children": [], 
    "id": "622c7ebf-067c-46ed-913a-ba045a0586df", 
    "visible": true, 
    "$$hashKey": "070" 
}, { 
    "name": "Front Curtain", 
    "weight": "1", 
    "value": "8", 
    "count": 0, 
    "min": 0, 
    "max": 0, 
    "children": [], 
    "id": "fe12c21c-e2c3-4702-ae9b-82f2fe248574", 
    "visible": true, 
    "$$hashKey": "071" 
}, { 
    "name": "Rear Curtain", 
    "weight": "1", 
    "value": "9", 
    "count": 0, 
    "min": 0, 
    "max": 0, 
    "children": [], 
    "id": "4a229ebb-d029-4b1e-a13d-246d00215900", 
    "visible": true, 
    "$$hashKey": "072" 
}, { 
    "name": "Fill-in", 
    "weight": "1", 
    "value": "10", 
    "count": 0, 
    "min": 0, 
    "max": 0, 
    "children": [], 
    "id": "a7ed372d-398f-4614-8efa-64a338f0ad20", 
    "visible": true, 
    "$$hashKey": "073" 
}, { 
    "name": "Wireless", 
    "weight": "1", 
    "value": "11", 
    "count": 0, 
    "min": 0, 
    "max": 0, 
    "children": [], 
    "id": "b36ab529-feab-42aa-8863-2a7084ac0aba", 
    "visible": true, 
    "$$hashKey": "074" 
}, { 
    "name": "Redeye Reduction with Slow Sync", 
    "value": "12", 
    "weight": "1", 
    "visible": true, 
    "id": "23ee6ac2-1b8b-41a7-ae80-aa4fcd8134ae", 
    "$$hashKey": "07F" 
}, { 
    "name": "Slow Rear-Curtain Sync", 
    "value": "13", 
    "weight": "1", 
    "visible": true, 
    "id": "f5835da6-4eac-4878-a8c0-3f91cd22372f", 
    "$$hashKey": "07J" 
}, { 
    "name": "Repeating or Strobe", 
    "value": "14", 
    "weight": "1", 
    "visible": true, 
    "id": "8f3bb252-ae6e-426a-9781-d1232a0a4845", 
    "$$hashKey": "0CW" 
}, { 
    "name": "Rear Sync", 
    "value": "15", 
    "weight": "1", 
    "visible": true, 
    "id": "d668aa49-a999-4638-8af2-5e9eaafd6e75", 
    "$$hashKey": "06L" 
}, { 
    "name": "Fill-Flaw", 
    "value": "16", 
    "weight": "1", 
    "visible": true, 
    "id": "00f92889-05f9-45fc-b3de-37e224991548", 
    "$$hashKey": "08D" 
}, { 
    "name": "Advanced Flash", 
    "value": "17", 
    "weight": "1", 
    "visible": true, 
    "id": "d49c3d25-2bf5-4723-b7d4-c3ae36783097", 
    "$$hashKey": "079" 
}, { 
    "name": "Fill-Flash", 
    "value": "18", 
    "weight": "1", 
    "visible": true, 
    "id": "4693db2a-19c7-4839-8e65-875e36416c63", 
    "$$hashKey": "0ER" 
}, { 
    "name": "Smart Flash", 
    "value": "19", 
    "weight": "1", 
    "visible": true, 
    "id": "8b04d59b-75cc-46ff-acc0-33f410f64a09", 
    "$$hashKey": "07D" 
}, { 
    "name": "", 
    "value": "", 
    "weight": "", 
    "visible": true, 
    "id": "18cec753-48fe-47e6-9e67-1bb36972bee4", 
    "$$hashKey": "07F" 
}, { 
    "name": "", 
    "value": "", 
    "weight": "", 
    "visible": true, 
    "id": "a7fbad1d-2a49-40e7-a9b1-520db0f9fc65" 
}] 

回答

3
<tr ng-repeat="val in attribute.format.values track by id"> 

這樣編輯

id可能是對象的標識,因此您可以通過id屬性來確定該屬性,如果您添加了兩個錯誤地共享相同id的對象,則會保留一個對象。

3

試試這個:

可以 '通過$索引道'

<tr ng-repeat="val in attribute.format.values track by $index"> 
+1

使用比接受的答案更好地工作 – 2014-09-23 11:36:04