ionic3 分页方法
开始写分页遇到很多问题。
自己写了一个分页方法 感觉还不错 分享给大家,不足之处多多指教。
//重点是这里的 sl 监听元素
getCardrecordList(page,sl){
let that = this;
if(this.card.begin_sell_time>this.card.end_sell_time){
this.tools.showToast("发卡的开始日期不能大于截止日期",2000);
return false;
}
this.hasdata =true;
let load = this.loadCtl.create({
content:"",
showBackdrop:false,
dismissOnPageChange:true
});
if(page=='1'){
this.card.curpage==1;
//回到顶部
}
load.present();
this.servers.cardrecordList(this.card,data=>{
load.dismiss();
if(data.code){
if(this.card.curpage==1){
this.ListInfo = data.data;
}else{
that.ListInfo =that.ListInfo.concat(data.data);
}
//无数据图片展示
if(this.ListInfo.length==0){
this.nodataPic = false;
}else{
this.nodataPic = true;
}
//判断分页 以及底部转圈效果
this.hasdata =false;
if(data.nextPage){
if(sl!=""){
sl.complete();
}
this.hasPage = true;
}else{
this.hasPage = false;
}
}
});
}
//下拉方法
doInfinite(infiniteScroll) {
this.card.curpage = this.card.curpage+1;
this.getCardrecordList('',infiniteScroll);
}
//页面内容
<ion-infinite-scroll (ionInfinite)="doInfinite($event)" infinite-scroll-distance="1%" *ngIf="hasPage">
<ion-infinite-scroll-content loadingSpinner="bubbles" loadingText="加载中"></ion-infinite-scroll-content>
</ion-infinite-scroll>