我有这个HTML
<ion-item ng-repeat="item in ::itemsToShow = extensionItems | orderBy:'distance' " class="entry" ng-class="{'alt-background': $index % 2 == 1}" ng-click="itemDetail(item)">
...details...
</ion-item>
我无法找出添加track by:item._id
的正确方法我总是收到此错误:
语法错误:令牌跟踪&#39;是表达式第30列的意外标记[itemsToShow = extensionItems track by:_id | ...
我试过了:
<ion-item ng-repeat="item in ::itemsToShow = extensionItems track by:item._id | orderBy:'distance' " class="entry" ng-class="{'alt-background': $index % 2 == 1}" ng-click="itemDetail(item)">
<ion-item ng-repeat="item in ::itemsToShow = extensionItems track by:_id | orderBy:'distance' " class="entry" ng-class="{'alt-background': $index % 2 == 1}" ng-click="itemDetail(item)">
<ion-item ng-repeat="item in ::itemsToShow = extensionItems | orderBy:'distance' track by:_id" class="entry" ng-class="{'alt-background': $index % 2 == 1}" ng-click="itemDetail(item)">
<ion-item ng-repeat="item in ::itemsToShow track by:_id = extensionItems | orderBy:'distance' " class="entry" ng-class="{'alt-background': $index % 2 == 1}" ng-click="itemDetail(item)">
还尝试使用_id
和item._id
并且我总是得到相同的错误(当然是不同的列)。我应该如何或在哪里写track by
?
修改:Angular版本1.4.3
编辑2 :Json数据具有此结构
_id: "000000426"
_rev: "1-5003008fcf25b8f130233b944bb761c9"
someText: "<p class="bodytext ">Something for you.</p>"
name : "You-Shop"
homepage : "http://www.youshop.com"
id: 426
答案 0 :(得分:0)
您错过了track by
必须不后跟冒号(:
)...
答案 1 :(得分:0)
`track by` MUST be the final statement in a ng-repeat.