问题
I have a function which basically reads data from firebase. I am trying to implement paging. Please see what i tried. I have seen other posts on this website but they are not very clear.
getFormData(pageSize:number,pageIndex:number,af:AngulrFireDatabase) {
Try1: Returning all records
----------------------------
return this.af.list('/forms').skip(pageIndex*pageSize).take(pageSize);
Try2: Not sure how to use the previous page last key value to pass to load the next page data.
-----------------------------
return this.af.list('/forms', {
query: {
orderByKey: true,
limitToFirst:pageSize
// How to skip the first few records here. for example if the page index is 2 then i have to ignore the first 2 pages data.
}
})
}
Any suggestions would be appreciated with a basic code example. Thank you.
回答1:
You can't skip a specific number of records. But you can tell Firebase at which item to start by specifying startAt: "keyAtWhichToStart"
.
The reason for not having offset based queries is that they don't work well in the context of realtime updates, which is what the Firebase Database was designed for.
I recommend also reading some of the many previous questions on pagination in the Firebase Realtime Database.
来源:https://stackoverflow.com/questions/48991973/firebase-paging-data-is-it-possible