2014-02-13 14 views
2

AngularDart ng-repeat指令似乎需要唯一值;例如,中如何使用AngularDart ng-repeat在可能带有重复项的简单值列表上使用

[NgErr50] ngRepeat error! Duplicates in a repeater are not allowed. 
    Use 'track by' expression to specify unique keys. 

假设从某些外部源获得的串列表以及值的唯一性无法保证以下

<li ng-repeat="x in ['Alice', 'Bob', 'Alice']">...</li> 

结果,如何能[NgErr50]避免?

+1

可能的重复[ng-repeat不能处理包含dupe的集合](http://stackoverflow.com/questions/20452223/ng-repeat-not-working-over-collections-that-c​​ontains-dupes) –

回答

6

这工作:

<li ng-repeat="x in ['Alice', 'Bob', 'Alice'] track by $index">...</li> 

有关更多选项,请参阅ng-repeat API docs

相关问题