在使用angularjs过程,ng-repeat中track by的作用
生活随笔
收集整理的這篇文章主要介紹了
在使用angularjs过程,ng-repeat中track by的作用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉載:http://segmentfault.com/q/1010000000405730<div?ng-repeat="links?in?slides">????<div?ng-repeat="link?in?links?track?by?$index">`link`.`name`</div></div>
Error: [ngRepeat:dupes]這個出錯提示具體到題主的情況,意思是指數組中有2個以上的相同數字。ngRepeat不允許collection中存在兩個相同Id的對象
For example:?item in items?is equivalent to?item in items track by $id(item). This implies that the DOM elements will be associated by item identity in the array.
對于數字對象來說,它的id就是它自身的值,因此,數組中是不允許存在兩個相同的數字的。為了規避這個錯誤,需要定義自己的track by表達式。例如:item in items track by item.id或者item in items track by fnCustomId(item)。嫌麻煩的話,直接拿循環的索引變量$index來用item in items track by $index
轉載于:https://blog.51cto.com/12762787/1910895
總結
以上是生活随笔為你收集整理的在使用angularjs过程,ng-repeat中track by的作用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: multi-mechanize erro
- 下一篇: 梦到自己眉毛没了怎么回事