在排序依据排除项目 [英] Exclude item on orderBy

查看:161
本文介绍了在排序依据排除项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我在 4项纳克重复。我怎样才能排除排序依据

Say I have 4 item in ng-repeat. How can I exclude one item in orderBy?

<li ng-repeat="item in items | orderBy:'id':true">

$scope.items = [
    {"name":"item1","id":1},
    {"name":"item2","id":2},
    {"name":"item3","id":3},
    {"name":"item4","id":4}
];

如何让,比如说ID:3始终显示为第一个项目

How can I make, say, id:3 always appear as the first item?

plunker演示

推荐答案

您可以创建一个函数来改变你的价值排序的(plunker)

You can create a function to alter the value you sort by (plunker):

$scope.itemSortValue = function(item) {
  if (item.id == 3)
    return -1;
  return item.id;
}

HTML:

<li ng-repeat="item in items | orderBy:itemSortValue">
  {{item.name}}
</li>

这篇关于在排序依据排除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆