admin管理员组文章数量:1313120
I am trying to order an array of objects by using a parator
function, but it seems the parator
function is pletely ignored (See the angular documentation).
I am using angularJS 1.5.6.
Here is a JSFiddle
Html:
<script src=".js/1.5.6/angular.min.js">
</script>
<body ng-app="app" ng-controller="ctrl">
{{msg}}
</body>
JavaScript:
angular.module("app", [])
.factory('f1', function($filter) {
var f1 = {};
function parator(a,b) { console.log(a,b); return a.id - b.id; }
function getter(x) { /*console.log(x);*/ return x; }
f1.testOrderBy = function() {
return $filter('orderBy')(
[ {id:3}, {id:1}, {id:2} ],
getter,
false,
parator
)
.map(function(x) { return x.id; })
};
return f1;
})
.controller("ctrl", function($scope, f1) {
$scope.msg = f1.testOrderBy();
})
My question: Why is parator
ignored? (This can be seen since the console.log()
call is never made). Is this an angularJS bug?
Because of this I cannot even order an array of objects using a custom parator.
Thanks!
I am trying to order an array of objects by using a parator
function, but it seems the parator
function is pletely ignored (See the angular documentation).
I am using angularJS 1.5.6.
Here is a JSFiddle
Html:
<script src="https://cdnjs.cloudflare./ajax/libs/angular.js/1.5.6/angular.min.js">
</script>
<body ng-app="app" ng-controller="ctrl">
{{msg}}
</body>
JavaScript:
angular.module("app", [])
.factory('f1', function($filter) {
var f1 = {};
function parator(a,b) { console.log(a,b); return a.id - b.id; }
function getter(x) { /*console.log(x);*/ return x; }
f1.testOrderBy = function() {
return $filter('orderBy')(
[ {id:3}, {id:1}, {id:2} ],
getter,
false,
parator
)
.map(function(x) { return x.id; })
};
return f1;
})
.controller("ctrl", function($scope, f1) {
$scope.msg = f1.testOrderBy();
})
My question: Why is parator
ignored? (This can be seen since the console.log()
call is never made). Is this an angularJS bug?
Because of this I cannot even order an array of objects using a custom parator.
Thanks!
Share Improve this question asked Jun 17, 2016 at 9:07 FlorisFloris 1,12312 silver badges27 bronze badges 2- 1 surprisingly the plunker example they gave on site is also not working as they explained in the documentation plnkr.co/edit/FSq6AwlpdCRmTEQ7hefL?p=preview – Deep Commented Jun 17, 2016 at 9:29
- Great catch Deep! Didn't even notice that! – Floris Commented Jun 17, 2016 at 9:48
1 Answer
Reset to default 13Because the support for custom parators in orderBy
was added in 1.5.7.
You can read the changelog here.
If you check the documentation for 1.5.6 you will see that the api is described as:
$filter('orderBy')(array, expression, reverse)
While in 1.5.7 it is:
$filter('orderBy')(collection, expression, reverse, parator)
本文标签: javascriptWhy does AngularJS orderBy filter ignore the comparator parameterStack Overflow
版权声明:本文标题:javascript - Why does AngularJS `orderBy` filter ignore the `comparator` parameter? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741874503a2402384.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论