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

来源:互联网 发布:海奇软件app 编辑:程序博客网 时间:2024/06/03 19:23


   错误原因


   今天前台接收到后台提交的数据以后,在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>

  

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

   



1 0
原创粉丝点击