如何使ngInfiniteScroll通过createdAt Descending检索数据

ado*_*srs 5 angularjs nginfinitescroll

我正在使用firebase来保存包含以下数据的帖子:

createdAt: "Sun Apr 03 2016 18:32:46 GMT-0300 (BRT)"
Run Code Online (Sandbox Code Playgroud)

我想要实现的是先获取最新帖子,然后在用户向下滚动时加载旧帖子.

使用ngInfiniteScroll检索的帖子我可以使用ngInfiniteScroll来命令desc <div ng-repeat="post in posts | orderBy:'-createdAt'">,然后首先返回旧帖子.我订购但是我订的是旧的.

我已经尝试"-createdAt"在ngInfiniteScroll中使用相同的逻辑()但它没有效果.


我的js就是这样的:

  var baseRef = new Firebase(FBURL).child("posts");
  var scrollRef = new Firebase.util.Scroll(baseRef, "createdAt");
  $scope.posts = $firebaseArray(scrollRef);
  $scope.posts.scroll = scrollRef.scroll;
Run Code Online (Sandbox Code Playgroud)

安全和规则:

"posts": {
          ".read": true,
          ".indexOn": "createdAt",
          "$post": {
            ".read": true,
            ".write": true,
            "$other": {
               ".validate": true
            }
         }
      }
Run Code Online (Sandbox Code Playgroud)

gar*_*mac 2

看起来您找到了解决方案,但您在正确的轨道上进行了管道安装,orderBy但只需尝试稍微调整一下即可。尝试使用orderBy:'+':true",其中orderBy表示您想按某些内容对其进行排序,并+:true表示在顶部有新内容的位置进行排序,在 -:true底部表示在底部排序新内容。但你可以在这里查看 Angular 文档。因此,如果在 HTML 端处理它,它会看起来像这样ng-repeat="post in posts| orderBy:'+':true"或者:

    <div ng-repeat="post in posts| orderBy:'+':true">
           [....post info here]
      </div>
Run Code Online (Sandbox Code Playgroud)

但请尝试一下,希望它有所帮助。