AngularJS如何对所有页面中的所有帖子进行排序?

时间:2016-04-23 16:01:26

标签: angularjs angularjs-ng-repeat

我想在所有页面中按pubdate对所有帖子进行排序。在询问之前,我试过了,但它没有成功。我的解决方案仅适用于第一页。 我做错了什么?为什么public static <T> LispList<T> pickEveryOtherHelper(LispList<T> ls, int counter) { LispList<T> wantLs = LispList.empty(); if(ls.isEmpty()) { return LispList.empty(); } else { if(counter % DIVIDER == 0) { // item we want wantLs = wantLs.cons(ls.head()); counter++; } else { // don't want item, look in tail pickEveryOtherHelper(ls.tail(), counter); } return wantLs; } } 无效?
JSFiddle:https://jsfiddle.net/7fqew8s5/2/
谢谢你的帮助。
附:对不起我的英语不好。我是乌克兰人。

1 个答案:

答案 0 :(得分:0)

简单排序数组$scope.items将解决此问题:

工作的jsfiddle在这里:https://jsfiddle.net/yufeng/5wz6nxun/

//Add the following code after the declaration of $scope.items
//sort the items by 'pubdate'
$scope.items.sort(function(a, b) {
    return b.pubdate - a.pubdate;
});