【问题标题】:ng-grid infinite scroll - ngGridEventScroll emited twiceng-grid 无限滚动 - ngGridEventScroll 发出两次
【发布时间】:2014-05-27 06:34:02
【问题描述】:

我尝试基于 ngGridEventScroll 事件实现无限滚动网格。但是每次滚动到网格底部时,我都会发出两次。 这是我更新数据的代码($scope.mydata 用作网格的源):

$scope.$on('ngGridEventScroll', function () {
    chunkStart += chunkSize;
    $http.get('/api/mydata/' + chunkStart + '/' + chunkSize)
          .success(function(mydata) {
                $scope.mydata = $scope.mydata.concat(mydata);
           });
});

我的错误在哪里,你能给我一些建议吗?

【问题讨论】:

    标签: javascript angularjs ng-grid


    【解决方案1】:

    我遇到了类似的问题,这是我的解决方案:

    $scope.load = true;
    $scope.$on('ngGridEventScroll', function() {
      if ($scope.load) {
        $scope.load = false;
        $http.get('your/url/here')
                .success(function(data) {
                  //operations here
                  $timeout(function() {
                    //or here
                    $scope.load = true;
                  });
                });
      }
    });
    

    我使用$scope.load 标志来指示何时加载数据和角度$timeout() 函数修复与时间相关的问题。

    【讨论】:

    • 我最终使用了这个解决方案,但我不得不为我的$timeout 添加一个小延迟,例如250
    猜你喜欢
    • 2020-11-05
    • 1970-01-01
    • 2020-04-07
    • 2019-03-30
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多