Firebase分页数据.可能吗? [英] Firebase paging data. Is it possible?

查看:131
本文介绍了Firebase分页数据.可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本上可以从Firebase读取数据的功能.我正在尝试实现分页.请看看我尝试了什么.我在该网站上看到过其他帖子,但它们不是很清楚.

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.

推荐答案

您不能跳过特定数量的记录.但是您可以通过指定 startAt:"keyAtWhichToStart" 来告诉Firebase从哪个项目开始.

You can't skip a specific number of records. But you can tell Firebase at which item to start by specifying startAt: "keyAtWhichToStart".

之所以没有基于偏移量的查询,是因为它们在实时更新的环境中无法正常运行,这正是Firebase数据库的设计目的.

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.

我还建议您阅读许多上一页Firebase实时数据库中有关分页的问题.

这篇关于Firebase分页数据.可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆