【问题标题】:How to retrieve the rows from starting and ending index in firebase database如何从firebase数据库中的开始和结束索引中检索行
【发布时间】:2019-12-27 05:28:15
【问题描述】:

我正在我的项目中尝试分页功能,我正在使用 react with firebase。

我的问题陈述:如果我的数据库中有大约 50 条记录,如果我们要选择记录 3 - 8,查询是什么?

【问题讨论】:

    标签: reactjs firebase firebase-realtime-database


    【解决方案1】:

    如果您想在前端使用特定字段,请使用切片,我认为您可以从后端返回所有列表,然后从 ui 端切片。

    let arr = [
    {id:1,name:'One'},
    {id:2,name:'Two'},
    {id:3,name:'Three'},
    {id:4,name:'Four'},
    {id:5,name:'Five'},
    {id:6,name:'Six'},
    {id:7,name:'Seven'},
    {id:8,name:'Eight'},
    {id:9,name:'Nine'},
    {id:10,name:'Ten'}
    ]
    let selected = arr.slice(2,8);
    console.log(selected)

    【讨论】:

    • 我需要一个 firebase 查询
    【解决方案2】:

    Firebase 实时数据库没有数字索引分页。 API 允许您使用startAt()limitToFirst() 和其他相关方法从头开始并翻阅查询结果,如documentation 中所述。

    如果您绝对必须使用索引,则必须读取整个结果集,填充一个数组,然后使用页面上所需的索引从该数组中挑选出所需的结果。

    【讨论】:

      猜你喜欢
      • 2016-11-12
      • 1970-01-01
      • 1970-01-01
      • 2020-02-17
      • 2020-01-07
      • 1970-01-01
      • 2016-11-27
      • 1970-01-01
      • 2013-12-11
      相关资源
      最近更新 更多