我知道可以用两个列分别对角度表进行排序,即先按名称排序然后按家庭排序。
https://plnkr.co/edit/bJIIlmGLyGWsxD5AQti0
var friends = [
{name: 'a', family: 'z', age: 10},
{name: 'z', family: 'b', age: 19},
{name: 'c', family: 'z', age: 21},
{name: 'z', family: 'd', age: 35},
{name: 'z', family: 'e', age: 29}
];
$scope.propertyName = 'age';
$scope.reverse = true;
$scope.friends = orderBy(friends, $scope.propertyName, $scope.reverse);
$scope.sortBy = function(propertyName) {
$scope.reverse = (propertyName !== null && $scope.propertyName === propertyName)
? !$scope.reverse : false;
$scope.propertyName = propertyName;
$scope.friends = orderBy(friends, ['name','family'], $scope.reverse);
};
}]);
})(window.angular);
我想知道是否可以通过组合两个字段对它们进行排序,例如按字母顺序排列“name”和“family”,因此它显示为“a,b,c,d,e”?
答案 0 :(得分:1)
您可以通过以下方式简单地将Array
传递给角度orderBy
过滤器:
ng-repeat="friend in friends | orderBy:['name', 'family']"
更新:在OP更改问题后,我要求您更好地说明所请求的订购功能,因为对我来说问题不是很清楚...
答案 1 :(得分:0)
<div ng-repeat="student in students | orderBy:['name','family']">
{{student.name}}-{{student.family}}
</div>