问题描述
track by必须位于表达式的末尾:
<li ng-repeat="person in attendees | filter: {arrived: false } track by person.id">
解决方法
我正在尝试根据布尔属性的值过滤一些列表项,但是无论我做什么,总会显示整个列表。我尝试过的一些东西已经坏掉了,什么也没显示,但这既不存在也不存在。我无法按需进行过滤:
$scope.attendees = [
{"firstname":"Steve","lastname":"Jobs","arrived":true,"id":1},{"firstname":"Michelle","arrived":false,"id":2},{"firstname":"Adam","lastname":"Smith","id":3},{"firstname":"Megan","id":4},{"firstname":"Dylan","id":5},{"firstname":"Ethan","id":6}
];
使用以下ng-repeat过滤:
<ul>
<li ng-repeat="person in attendees track by person.id | filter:arrived:'false'">
{{person.lastname}},{{person.firstname}}
</li>
</ul>
我觉得我已经尝试了所有可以找到引用的排列,其中大部分来自各种StackOverflow搜索结果:
filter:'arrived'
filter:arrived
filter:'person.arrived'
filter:person.arrived
filter:{arrived:true}
filter:{arrived:'true'}
filter:{person.arrived:true}
filter:{person.arrived:'true'}
我也尝试过创建自定义过滤器功能:
$scope.isArrived = function(item) {
return item.arrived;
};
并因此应用它:
filter:isArrived
filter:'isArrived'
filter:{isArrived(person)}
filter:isArrived(person)
filter:'isArrived(person)'
这些似乎都不起作用。我想念什么?