1

我如何检查是否必须停止调用该loadMore()函数,因为所有文档都已从数据库中加载?

在下面的示例中,我使用的是 Ionic,但 AngularJS 应用程序中的 ng-infinite-scroll 也是如此。

这是我的实际代码:

HTML:

  ...

  <ion-infinite-scroll
    ng-if="!noMoreItemsToLoad"
    on-infinite="loadMore()"
    distance="5%">
  </ion-infinite-scroll>

</ion-content>

JS 控制器:

$scope.loadMore = function(){

  console.log('Loading more docs...');

  Items.loadMore();  // calling the .next() method inside the Items service

  if( !Items.hasNext()) { $scope.noMoreItemsToLoad = true; }

  $scope.$broadcast('scroll.infiniteScrollComplete');

}

JS 物品工厂:

.factory('Items', function (FIREBASE_URL, $firebaseArray,  $firebaseObject) {

  var itemsRef = new Firebase(FIREBASE_URL + 'items/');
  var scrollRef = new Firebase.util.Scroll(itemsRef, 'name');

  var self = {
     getAllItems : function(){ ... },

     loadMore: function(){
       scrollRef.scroll.next(4);
     },

     hasNext: function(){
       if(scrollRef.scroll.hasNext()) { return true; }
       else { return false; }
     }
  }

  return self;

}
4

2 回答 2

1

执行scroll.nextin 超时,例如:

 loadMore: function(){
   $timeout(function() {
     scrollRef.scroll.next(4);
   });
 },
于 2016-12-28T15:40:58.670 回答
0

我有同样的问题,我认为解决方案是修改 firebase.util.js 上的 hasNext() 函数:

Cache.prototype.hasNext = function() {
  return this.count === -1 || this.endCount >= this.start + this.count;
};

我在this.start之前添加了一个缺少的等号 (=)

我希望这个对你有用。

于 2016-04-19T11:40:15.180 回答