無限滾動在將新數據添加到頁面之前清除現有數據 - infinite scroll clears existing data before adding new data unto page -开发者知识库

無限滾動在將新數據添加到頁面之前清除現有數據 - infinite scroll clears existing data before adding new data unto page -开发者知识库,第1张

I'm working on an ionic project which contains infinite scrolling. When users scroll to the bottom of the page it loads up older posts by first clearing up what existed on the page except for it.

我正在研究一個包含無限滾動的離子項目。當用戶滾動到頁面底部時,它首先清除頁面上除了它之外的內容,從而加載舊帖子。

Controller

app.controller('feedsctrl', ['$scope', '$http', function($scope,$http) {
    $scope.posts = [];
    $scope.page=0;
    $scope.loadmore = function() {
        $http.get('http://localhost/app/news.php?page=' $scope.page).success(function(data) {
            console.log(JSON.stringify(data));
            var i = data.length;
            $scope.posts = data;
            $scope.posts.push(data);
            $scope.$broadcast('scroll.infiniteScrollComplete');
            //console.log($scope.page);
            $scope.page  =1;
        });
    };
}]);

HTML

<div ng-controller="feedsctrl" class="list card" ng-repeat="item in posts track by $index">
{{item.fullname}}<br>
{{item.username}}
</div>

1 个解决方案

#1


1  

.controller('feedsctrl',['$scope','$http',function($scope,$http){
  $scope.posts = [];
  $scope.page=0;
  $scope.loadmore = function() {
    $http.get('http://localhost/app/news.php?page=' $scope.page).success(function(data) {
      for(var i=0;i<data.length;i  ){
      $scope.posts.push(data[i]);
      }
      $scope.$broadcast('scroll.infiniteScrollComplete');
      //console.log($scope.page);
      $scope.page  =1;
    });
  };
}])

You are assigning data into $scope.posts before pushing it .You shouldn't be

您在推送之前將數據分配到$ scope.posts。您不應該這樣做

Thanks

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复