加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS orderBy不工作跟踪by ngOptions?

发布时间:2020-12-17 09:02:18 所属栏目:安全 来源:网络整理
导读:我试图排序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
我试图排序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来演示这个。这个问题是排序不工作。我应该写一个自定义过滤器吗?

为了使用带过滤器的跟踪,需要在过滤器之后添加跟踪表达式。

试试这个:

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读