在使用firebase.com作为数据库的应用程序中进行分页 [英] Pagination in application which use firebase.com as database

查看:114
本文介绍了在使用firebase.com作为数据库的应用程序中进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前端应用程序将使用firebase.com作为数据库。
应用程序应该像博客一样工作:

管理员添加/删除帖子。



这里有home页面,每页显示几篇文章,Next和Prev按钮以及显示单个文章的页面。 b

另外我需要深度链接。
I.e.当用户输入URL http://mysite.com/page/2/ 我需要该应用程序显示最后文章从10到20,当用户输入URL http://mysite.com/page/20/ 应用程序显示最后的文章从200到210.通常分页。



主要问题 - 是否有可能实现这一点,如果使用firebase.com。



我在firebase.com阅读文档,我在这里阅读帖子。
















$ b <基于这个我想这个:


  • 添加POST动作:



  • 获取帖子计数器的值

  • 设置新帖子数据的优先级等于帖子计数器的值

  • DELETE POST操作


    1. 获取发布数据的优先级值

    2. 查询发布数据的优先级高于优先级的数据将被删除并降低其值
    3. $

    4. 从$ x到y

      获取职位$ b $


      1. postsRef.startAt(null,x).endAt(null,y).on(...等等)
        ol>



      2. 我不喜欢的东西是DELETE POST的动作。因为帖子的索引将从0到无穷大,并且优先级较低的帖子被认为是之前创建的帖子,所以如果我有100000000帖子,并且如果我需要删除第一帖子,那么我需要为99999999个下一帖子加载数据并更新它们优先权(索引)。


        解决方案

        正如你所提到的,offset()将会到来,这使得你的工作更容易。同时,不是将startAt和endAt结合使用,而是可以使用startAt和limit进行组合,以确保总能得到N个结果。这样,删除的项目将被跳过。然后,您需要检查每个页面的最后一个ID,然后才能找到正确的ID。


        Front end application will use firebase.com as database. Application should work like blog:

        Admin add / remove posts.

        There are "home" page which show several articles per page with "Next" and "Prev" buttons and page which show single article.

        Also I need deep linking. I.e. when user enter URL http://mysite.com/page/2/ I need that application show last articles from 10 to 20, when user enter URL http://mysite.com/page/20/ application show last articles from 200 to 210. Usual pagination.

        Main question - is it possible to achieve this if use firebase.com.

        I read docs at firebase.com, I read posts here. "offset()" and "count()" will be in the future, use priority, in order to know count of items and not load all of them use additional counter.

        Based on this I suppose this:

        • ADD POST action:

          1. get value of posts counter
          2. set priority for new post data equals to value of posts counter
          3. increase value of posts counter

        • DELETE POST action

          1. get value of priority for post data
          2. query posts data which have value of priority more than priority for post data which will be deleted and decrease their value
          3. decrease value for posts counter

        • GET POSTS FROM x TO y

          1. postsRef.startAt(null, x).endAt(null, y).on(... and so on)

        Thing which I not like in this way are actions for DELETE POST. Because index of posts will be from 0 to infinity and post with less priority is considered as post which was created earlier so if I have 100000000 posts and if I need to delete 1st post then I need to load data for 99999999 next posts and update their priority (index).

        Is there any another way?

        Thanks in advance, Konstantin

        解决方案

        As you mentioned, offset() will be coming, which makes your job easier.

        In the meantime, rather than using startAt and endAt in combination, you could use startAt and limit in combination to ensure you always get N results. That way, deleted items will be skipped. You then need to check the last id of each page before moving to the next to find the proper id to start on.

        这篇关于在使用firebase.com作为数据库的应用程序中进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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