【发布时间】:2021-01-19 01:11:50
【问题描述】:
我是 ionic 新手,我不知道如何进行无限滚动。看了几篇文档没看懂 这是我的主页https://prnt.sc/usjd2r。我想要的是在 15-20 项之后,无限滚动起作用并出现新的 15-20 项。
这是我的主页.ts:
ngOnInit() {
this.presentLoading()
//this.items2 = this.db.list('/forms').valueChanges();
//this.items2.forEach(a=>console.log(a))
}
async presentLoading() {
const loading = await this.loadingController.create({
cssClass: 'my-custom-class',
message: 'Please wait...',
showBackdrop:true,
duration:2500
});
await loading.addEventListener('ionLoadingWillPresent', (event: any) => {
this.allForms=[]
this.mainS.getAllForms().subscribe(x=>{this.allForms = x
this.allForms.sort((b, a) => new Date(b.startDate).getTime() - new Date(a.startDate).getTime())
this.filterData = this.allForms
})
firebase.auth().onAuthStateChanged(user=> {
if (user) {
this.db.object('/users/' + user.uid+"/control").snapshotChanges().subscribe(c=>this.control = c.payload.val())
} else {
}
});
});
await loading.present();
await loading.onDidDismiss().then(x=>this.c=true);
console.log('Loading dismissed!');
}
getAllForms:
getAllForms(){
return this.db.list('/forms/' ).snapshotChanges().pipe(map(changes => changes
.map(c => ({key: c.payload.key, ...c.payload.val() as {}}))));
}
这是主要的html:
<ion-content *ngIf="c" >
<ion-searchbar [(ngModel)]="searchTerm" (ionInput)="setFilteredLocations($event)"></ion-searchbar>
<ion-grid >
<ion-row>
<ion-col size="12" size-sm="8" offset-sm="2" text-center>
<ion-list>
<ion-item *ngFor="let forms of filterData" >
<ion-thumbnail slot="start">
<ion-img [src]="forms.pp" (click)="openModel(forms.who)"></ion-img>
</ion-thumbnail>
<ion-label >
<h5>{{forms.name}}</h5>
</ion-label>
<ion-label >
<h5>{{forms.place}}</h5>
</ion-label>
<ion-label >
<h5>{{forms.startDate}}</h5>
</ion-label>
<ion-button slot="end" (click)="goFor(forms.key)" fill="clear">
<ion-icon name="arrow-forward-outline" slot="icon-only"></ion-icon>
</ion-button>
</ion-item>
</ion-list>
</ion-col>
</ion-row>
</ion-grid>
</ion-content>
【问题讨论】:
-
这看起来不像是在尝试实现无限滚动。你读过这个? ionicframework.com/docs/api/infinite-scroll
-
是的,谢谢你的帮助,我做到了
标签: angular ionic-framework firebase-realtime-database