您的位置:首页 > 其它

[ngRepeat:dupes] Duplicates in a repeater are not allowed. Use 'track by' expression to specify uniq

2016-07-06 20:31 417 查看
   错误原因

   今天前台接收到后台提交的数据以后,在view进行ng-reapet绑定数据的时候出现以下脚本错误:

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

   上面这句代码大概的意思:错误是内容相同引起的。

    view中的代码是这样写的:

<span style="font-family:SimSun;font-size:18px;"><span ng-repeat="tempExaminant in item.examinant ">{{tempExaminant}}</span></span>


   小编用fiddler跟踪了一下,的确是返回的数据中有重复的数据,不知道为什么angular的指令会有这样的限

制,那么如果我们必须显示重复数据怎么办呢,我们需要在ng-repeat后面添加track by $index

   view中的代码改成这样:

<span style="font-family:SimSun;"> <span ng-repeat="tempExaminant in item.examinant track by $index ">{{tempExaminant}}</span></span>

  
   这样我们就可以解决遍历重复数据问题了。

   
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: