Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 离子无限滚动与http_Javascript_Jquery_Angularjs - Fatal编程技术网

Javascript 离子无限滚动与http

Javascript 离子无限滚动与http,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我的密码员怎么了? 我使用API获取数据,当无限滚动时,API数据立即出现在滚动之前 <body ng-controller="MyCtrl"> <ion-header-bar class="bar-positive"> <h1 class="title"><span class="badge badge-assertive">{{items.length}}</span> Items loaded</h1&

我的密码员怎么了? 我使用API获取数据,当无限滚动时,API数据立即出现在滚动之前

<body ng-controller="MyCtrl">

    <ion-header-bar class="bar-positive">
      <h1 class="title"><span class="badge badge-assertive">{{items.length}}</span> Items loaded</h1>
    </ion-header-bar>

    <ion-content>

      <ion-list>
        <ion-item ng-repeat="item in items" 
                  item="item"
                  href="#/item/{{item.id}}">
          Item {{ item }}
        </ion-item>
      </ion-list>
      <ion-infinite-scroll
        on-infinite="loadMore()"
        distance="10%">
      </ion-infinite-scroll>
    </ion-content>  

{{items.length}}已加载项
项目{{Item}

JS

.controller('MyCtrl',函数($scope,$http){
$http.get(“#”,{withCredentials:true})
.成功(功能(响应){
$scope.items=response.products;
}).错误(功能(响应)
{
$scope.status=响应| |“请求失败”;
});
$scope.items=[];
$scope.loadMore=函数(){
var数据=[];
var l=$scope.items.length
对于(变量i=l;i
我会遵循这个准则

要记住的几点:

  • 从http请求中获取分页数据
  • 根据您的需求管理代码中的isMoreItems变量
  • 调用
    $scope.$broadcast('scroll.infiniteScrollComplete')
    每当滚动加载完成时
如果你遵循以上几点,你的问题就会解决。

看看这个

var offset = 1; 
var max = 10; 
var customer = 2;
vm.customerList = [];
var url= '/some/some/?customer='+'customer'+'&offset='+offset+'&max='+max;
$http.get(url).success(function (response) { 
var customerResponse = response.data;    
angular.forEach(customerResponse,function(response){    
vm.customerList.push(response);  
$scope.$broadcast('scroll.infiniteScrollComplete'); });
        }).error(function (err) {
    $scope.$broadcast('scroll.infiniteScrollComplete');
      })

只有代码的答案被认为是低质量的。还要解释这是如何解决问题的。
<ion-infinite-scroll ng-if="isMoreItems" on-infinite="loadMore()" distance="10%"></ion-infinite-scroll>
var l = $scope.items.length
if(l == 0){
  $scope.isMoreItems = false;
}else{
   for ( var i = l; i < l+5; i++) {
      data.push(i);
   }
   $scope.$apply(function () {
     $scope.items = $scope.items.concat(data);
   });

   $scope.isMoreItems = true;

   $scope.$broadcast('scroll.infiniteScrollComplete');
}
var offset = 1; 
var max = 10; 
var customer = 2;
vm.customerList = [];
var url= '/some/some/?customer='+'customer'+'&offset='+offset+'&max='+max;
$http.get(url).success(function (response) { 
var customerResponse = response.data;    
angular.forEach(customerResponse,function(response){    
vm.customerList.push(response);  
$scope.$broadcast('scroll.infiniteScrollComplete'); });
        }).error(function (err) {
    $scope.$broadcast('scroll.infiniteScrollComplete');
      })