获取特定范围的Firebase数据库子级 [英] Get specific range of Firebase Database children

查看:30
本文介绍了获取特定范围的Firebase数据库子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如我的Firebase实时数据库中有下一个数据(我的json文件包含一些对象的json数组):

E.g. I have next data in my Firebase Realtime Database (my json file contains json array of some objects):

我想让所有对象从特定索引(位置)开始到该数组的末尾(在Firebase DB中,json数组被转换为包含键为001、002等子项的简单对象)

I would like to get all objects starting from a specific index (position) to the end of this array (in Firebase DB json array is converted to simple object which contains children with keys 001, 002 and so on)

所以我需要类似的内容,但需要进行Firebase查询:

So I need something like this but for Firebase query:

list.subList(10, list.size)

我知道有 limitToFirst limitToLast 个方法,但这是不同的

I know there are limitToFirst, limitToLast methods but it's different

fireDatabaseReference.child("episodes").limitToLast(10)

它无法满足我的需求.因为我需要知道此数组的大小,并且我需要确保在有人提出这样的请求时,该数组不会变大(在某些时候,由于添加新对象,该数组可能会变大)

It won't do what I need. Because I need to know the size of this array and I need to be sure that this array won't become bigger at the moment someone makes such request (at some point this array can get become bigger due to adding new objects)

拥有一个类似 from 的方法来将所有子级从10到末尾(所以排除了前9个子级)将是很棒的:

Would be great to have a method like from to get all children from 10 to the end (so first 9 children are excluded):

fireDatabaseReference.child("episodes").from(10)

但是没有这样的方法

有什么解决办法吗?

推荐答案

已解决:)

fireDatabaseReference.child("episodes").orderByKey().startAt("10")

这篇关于获取特定范围的Firebase数据库子级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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