在Angular中有多个字段

本文翻译自:orderBy multiple fields in Angular

How to sort by using multiple fields at same time in angular? 如何在角度中同时使用多个字段进行排序? fist by group and then by sub-group for Example 按组分组,然后按分组示例

$scope.divisions = [{'group':1,'sub':1}, {'group':2,'sub':10}, {'group':1,'sub':2},{'group':1,'sub':20},{'group':2,'sub':1},
    {'group':2,'sub':11}];

I wanted to display this as 我希望将其显示为

group : Sub-group 组:子组

1 - 1 1 - 1

1 - 2 1 - 2

1 - 20 1 - 20

2 - 1 2 - 1

2 - 10 2 - 10

2 - 11 2 - 11

<select ng-model="divs" ng-options="(d.group+' - '+d.sub) for d in divisions | orderBy:'group' | orderBy:'sub'" />

#1楼

参考:https://stackoom.com/question/19UEm/在Angular中有多个字段


#2楼

Please see this: 请看这个:

http://jsfiddle.net/JSWorld/Hp4W7/32/ http://jsfiddle.net/JSWorld/Hp4W7/32/

<div ng-repeat="division in divisions | orderBy:['group','sub']">{{division.group}}-{{division.sub}}</div>

#3楼

<select ng-model="divs" ng-options="(d.group+' - '+d.sub) for d in divisions | orderBy:['group','sub']" />

用户数组而不是多个orderBY


#4楼

If you wants to sort on mulitple fields inside controller use this 如果你想对控制器内的多个字段进行排序,请使用此方法

$filter('orderBy')($scope.property_list, ['firstProp', 'secondProp']);

See also https://docs.angularjs.org/api/ng/filter/orderBy 另见https://docs.angularjs.org/api/ng/filter/orderBy


#5楼

There are 2 ways of doing AngularJs filters, one in the HTML using {{}} and one in actual JS files... 有两种方法可以使用AngularJs过滤器,一种在HTML中使用{{}},一种在实际的JS文件中......

You can solve you problem by using : 您可以使用以下方法解决问题:

{{ Expression | orderBy : expression : reverse}}

if you use it in the HTML or use something like: 如果你在HTML中使用它或使用类似的东西:

$filter('orderBy')(yourArray, yourExpression, reverse)

The reverse is optional at the end, it accepts a boolean and if it's true, it will reverse the Array for you, very handy way to reverse your Array... 反面是可选的,它接受一个布尔值,如果是真的,它将为你反转数组,非常方便的方式来反转你的数组...


#6楼

Make sure that the sorting is not to complicated for the end user. 确保最终用户的排序不复杂。 I always thought sorting on group and sub group is a little bit complicated to understand. 我一直认为对组和子组进行排序有点复杂。 If its a technical end user it might be OK. 如果它是技术最终用户,那可能没问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值