Firebase 分页数据.是否可以? [英] Firebase paging data. Is it possible?

查看:36
本文介绍了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.

我建议您还阅读许多 previousFirebase 实时数据库中的分页问题.

I recommend also reading some of the many previous questions on pagination in the Firebase Realtime Database.

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

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