我试图排序ngOptions跟踪
这是我的模板
<select ng-model="asd" ng-options="user.id as user.name for user in users track by user.id | orderBy: 'name'">
这是我的控制器
function AppCtrl($scope) { $scope.users = [ {id : 25,name: 'Batista'},{id : 26,name: 'Ultimate Warrior'},{id : 27,name: 'Andre the giant'} ]; $scope.name = 'asdasd'; $scope.asd = 25; }
我写了一个snippet in JSBin来演示这个。这个问题是排序不工作。我应该写一个自定义过滤器吗?
为了使用带过滤器的跟踪,需要在过滤器之后添加跟踪表达式。
原文链接:https://www.f2er.com/angularjs/146621.html试试这个:
user.id as user.name for user in users | orderBy: 'name' track by user.id
ngRepeat
的文档在“Arguments”部分提到了这一点,具体来说:
Filters should be applied to the expression,before specifying a tracking expression.
和
For example: item in items | filter:searchText track by item.id is a pattern that might be used to apply a filter to items in conjunction with a tracking expression.