如何在可能具有重复项的简单值列表上使用 AngularDart ng-repeat [英] How to use AngularDart ng-repeat over a list of simple values possibly with duplicates
本文介绍了如何在可能具有重复项的简单值列表上使用 AngularDart ng-repeat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
AngularDart ng-repeat
指令似乎需要唯一值;例如,以下
The AngularDart ng-repeat
directive seems to require unique values; e.g., the following
<li ng-repeat="x in ['Alice', 'Bob', 'Alice']">...</li>
结果
[NgErr50] ngRepeat error! Duplicates in a repeater are not allowed.
Use 'track by' expression to specify unique keys.
假设字符串列表是从某个外部来源获得的,并且不保证值的唯一性,如何避免[NgErr50]
?
Assuming that the list of strings is obtained from some external source and that uniqueness of values is not guaranteed, how can the [NgErr50]
be avoided?
推荐答案
这有效:
<li ng-repeat="x in ['Alice', 'Bob', 'Alice'] track by $index">...</li>
有关更多选项,请参阅 ng-repeat API 文档.
For more options, see the ng-repeat API docs.
这篇关于如何在可能具有重复项的简单值列表上使用 AngularDart ng-repeat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文