Ionic 2禁用无限滚动微调器

时间:2022-07-05 22:57:46

I have an infinite scroll working perfectly, however, when I get to the end of my data, the spinner still spins. How do i stop the spinner?

我有一个完美的无限卷轴,然而,当我到达我的数据的末尾时,旋转器仍然旋转。我如何阻止微调器?

As you can see, I am setting hasMoreData to false, but the spinner still spins.

正如您所看到的,我将hasMoreData设置为false,但是微调器仍在旋转。

Thanks

html

  <ion-infinite-scroll *ngIf="hasMoreData" (ionInfinite)="doInfinite($event)">
    <ion-infinite-scroll-content></ion-infinite-scroll-content>
  </ion-infinite-scroll>

ts

doInfinite(infiniteScroll: InfiniteScroll) {
    this.firstResult += this.MAX_RESULTS;
    var promise: Promise<EmployeeModel[]>;
    promise = this.employeeService.getEmployeeRangeSearch(this.firstResult, this.MAX_RESULTS, this.latitude, this.longitude, this.maxDistance, this.miles, this.searchQuery);
    promise.then((employeeModels: EmployeeModel[]) => {
      for (var index = 0; index < employeeModels.length; index++) {
        this.employeeModels.push(employeeModels[index]);
      }
      if (employeeModels.length === 0) {
        infiniteScroll.enable(false);
        this.hasMoreData = false;
      } else {
        infiniteScroll.enable(true);
        this.hasMoreData = true;
      }
      infiniteScroll.complete();
    });
  }

1 个解决方案

#1


0  

You need call function enable(false) when data is end.

数据结束时需要调用函数enable(false)。

doInfinite(infiniteScroll) {
    //  Do your process
   // ..

  //if you no longer have data, usually in the asynchronous response of your call
  if(hasMoreData){
     infiniteScroll.enable(false);
  }

}

Just this already worked for me!

这已经对我有用了!

#1


0  

You need call function enable(false) when data is end.

数据结束时需要调用函数enable(false)。

doInfinite(infiniteScroll) {
    //  Do your process
   // ..

  //if you no longer have data, usually in the asynchronous response of your call
  if(hasMoreData){
     infiniteScroll.enable(false);
  }

}

Just this already worked for me!

这已经对我有用了!