猿问

在ionic2中我想先通过http请求一部分,然后剩下的数据用 ion-infinite-

doInfinite(infiniteScroll) {


console.log('Begin async operation');

setTimeout(() => {

  for (let i = 0; i < 5; i++) {

    if(this.items.length < 20){

      this.items.push( this.items.length ); 

      infiniteScroll.complete();         

    }else{

      infiniteScroll.enable(false);

    }

  }

  console.log('Async operation has ended');

}, 500);

}


ionViewDidLoad(){


this.http.get('assets/data/nearby.json')

.subscribe(data=>{

  console.log(data)

  console.log(data.json())

  this.lists = data.json()

},error=>{

  console.log(error)

});

}

}


HUWWW
浏览 535回答 1
1回答

MM们

通过控制loadMore判断是否有加载更多 参考代码示例<ion-infinite-scroll (ionInfinite)="doInfinite($event)" [threshold]="'10%'" [enabled]="loadMore">&nbsp; &nbsp; &nbsp; &nbsp; <ion-infinite-scroll-content [loadingSpinner]="'bubbles'">&nbsp; &nbsp; &nbsp; &nbsp; </ion-infinite-scroll-content>&nbsp; &nbsp; </ion-infinite-scroll>doInfinite(infiniteScroll) {&nbsp; &nbsp; let id = this.lists[this.lists.length - 1]["id"];&nbsp; &nbsp; let params = {&nbsp; &nbsp; &nbsp; 'Id': id,&nbsp; &nbsp; &nbsp; 'getPast': 'true'&nbsp; &nbsp; };&nbsp; &nbsp; this._demoService.list(params)&nbsp; &nbsp; &nbsp; .subscribe((result) => {&nbsp; &nbsp; &nbsp; &nbsp; if (result.data.length > 0) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.lists = this.lists.concat(result.data);&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; infiniteScroll.complete();&nbsp; &nbsp; &nbsp; &nbsp; this.loadMore = result.data.length == 10;&nbsp; //一次请求多少条&nbsp; &nbsp; &nbsp; }, (err) => {&nbsp; &nbsp; &nbsp; &nbsp; infiniteScroll.complete();&nbsp; &nbsp; &nbsp; });&nbsp; }
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答