gpt4 book ai didi

javascript - 如何查询 Firebase 两个键之间的值

转载 作者:行者123 更新时间:2023-12-03 02:19:32 26 4
gpt4 key购买 nike

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

示例

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

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

“end”键可以为空,我的 firebase 数据库中的数组位于下面

"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"
},

最佳答案

您只能查询一个子项,因此可以选择 startend 子项。

你可以做的是:

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

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

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

这将为您提供子 start 的前 5 个

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

关于javascript - 如何查询 Firebase 两个键之间的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49220652/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com