AngularJS:orderBy [英] AngularJS: orderBy

查看:47
本文介绍了AngularJS:orderBy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我得到了一个带有某些名称的ng-repeat.我想做的是跟随.输出到屏幕的名称按字母顺序排列.

So i have got a ng-repeat with some names in it. What i want to do is following. The names that are outputted to the screen are ordered alphabetically.

名称中的

< div ng-repeat =" |orderBy:'name''></div>

  • 安妮
  • 约翰
  • 迈克
  • Ziggy

但是是否可以始终将名字"Mike"作为姓氏,其余字母按字母顺序排列?

But is it possible to always show the name 'Mike' as the top name and order the rest alphabetically?

  • 迈克
  • 安妮
  • 约翰
  • Ziggy

推荐答案

您可以为此编写其他排序功能.例如:

You can write additional sorting function for this. For example:

HTML:

<div ng-repeat="n in names | orderBy:[egoSort, 'name']">{{n}}</div>

控制器:

$scope.egoSort = function(name) {
    return name === 'Mike' ? '' : name;
};

之所以可行,是因为 orderBy 允许您使用数组表示法指定多个谓词.

This is possible because orderBy allows you to specify several predicates using array notation.

这篇关于AngularJS:orderBy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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