我无法弄清楚如何对以下场景进行分页。请告诉我是否有更简单的方法,我让它变得复杂。它使用Ionic 3和firestore。
show.html
<ion-row *ngFor="let item of observable | async">
{{item.value}}
</ion-row>
<ion-infinite-scroll (ionInfinite)="doInfinite($event)">
<ion-infinite-scroll-content></ion-infinite-scroll-content>
</ion-infinite-scroll>
</ion-content>
show.ts
observable: Observable<any[]>;
this.observable = this.provider.getData(); //in the corstructor method
provider.ts
getData(){
return this.afs.collection('data').limit(10).snapshotChanges().map(a=>{
return a.map(x=> {
return {
value: x.payload.doc.data(),
};
});
});
}
所以,我从provider.ts调用一个方法,在我的show.ts文件中将集合列表作为observable。 observable将显示在带有async
竖管
为了对firestore进行分页,我必须使用startAt(dataSnap)
或startAfter(dataSnap)
。要使用这些方法,我需要集合的最后一个数据快照。如何从观察中获取最后一项?
不知道如何继续这种方法。