Firebase paging data. Is it possible?

↘锁芯ラ 提交于 2020-01-16 09:08:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!