angularJS ng-repeat = "item in XXX track by $ index" problem record

Reference: https://blog.csdn.net/lunhui1994_/article/details/80236315

 

Question: project data to do a paging effect, the ideal is: When more than 6 pages, hidden> Page 6. Click Previous, Next time, the corresponding number is highlighted. The current page is page 6, when you click Next, the serial number can not always highlighted.

The reason : ng-repeat = "item in pagenum track by $ index" - track by $ index phrase in question

    Since the $ index will follow the item move down, or will be deleted. (For example, you take a list of the second and first position swap, this time the list is now first in the index is still 2, the second or the original 1) This time you re-use 'index still is 2, the second Article 1 or the original) this time you re-use the `index is still 2, the second or the original 1) this time you re-use 'index` transfer value is not in the index of the new array, and no longer match

    When I make a start number array pagenum only take the first six, the current page is page 6, and then loaded back pages when you click Next, reorder the pagenum, so out of the question.

  

Solution: remove the "track by $ index" or you can sort by other unique mark.

Guess you like

Origin www.cnblogs.com/linjiangxian/p/11654750.html