在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


用户数组而不是多个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. 如果它是技术最终用户,那可能没问题。

你可能感兴趣的:(在Angular中有多个字段)