ng-repeat错误:“不允许在转发器中重复”

时间:2014-09-23 11:12:40

标签: javascript angularjs

这是我的HTML,

<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"
}]

2 个答案:

答案 0 :(得分:3)

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

像这样编辑

id可以是对象的标识,因此您可以通过id属性进行处理,如果您添加了两个错误地共享相同id的对象,则会保留一个对象。 / p>

答案 1 :(得分:3)

试试这个:

你可以使用'追踪$ index'

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