如何查询Firebase两个键之间的值 [英] How to query Firebase for value between two keys

查看:53
本文介绍了如何查询Firebase两个键之间的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用值搜索Firebase数据,如果值介于两个键之间,我想获取数据

How can i search firebase data with a value, i want to get the data if the value comes in between the two keys

示例

如果用户输入1到5之间的任何数字,则返回以下数据,

If user enter any number between 1 to 5 return the below data,

"start" : "1",
"end" : "5",

"end"键可以为空,我的Firebase数据库中的数组在下面

"end" key can be empty, the array i have in my firebase database is below

"classdata" : [ null, {
      "-L4VflG9efJfNOk0ETjK" : {
        "start" : "1",
        "end" : "2",
        "classdate" : 1517761011016,
        "commentator" : "",
        "description" : "",
        "id" : 1517745488337,
        "title" : "12"
      },
      "-L4WUbRH46l3pIcwDC2z" : {
        "start" : "3",
        "end" : "",
        "classdate" : 1518961333727,
        "commentator" : "",
        "description" : "",
        "id" : 1517759080685,
        "title" : "5"
      },
      "-L4WbgyUB7MRVUzBNJM3" : {
        "start" : "4",
        "end" : "6",
        "classdate" : 1518975293250,
        "commentator" : "",
        "description" : "",
        "id" : 1517761201012,
        "title" : "2"
      },
      "-L5cxhQzDkEHrFi6J5Mf" : {
        "start" : "7",
        "end" : "",
        "classdate" : 1519010573333,
        "commentator" : "",
        "description" : "",
        "id" : 1518958204014,
        "title" : "1"
      },

推荐答案

您只能查询一个孩子,所以 start end 子对象.

You can only query on one child so either start or end child.

您可以做的是这样:

ref.orderByChild("start").equalTo("4").on(...){...};

上面将为您提供start = 4时的值

The above will give you the values when start=4

ref.orderByChild("start").limitToFirst(5).on(...){..};

这将为您提供孩子的第5个 start

this will give you the first 5 of child start

ref.orderByChild("start").startAt("1").endAt("5").on(..){..};

这篇关于如何查询Firebase两个键之间的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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