gpt4 book ai didi

ios - Firebase QueryOrderedByChild 以及 EqualToValue 和 StartingAtValue 组合

转载 作者:搜寻专家 更新时间:2023-11-01 06:18:33 25 4
gpt4 key购买 nike

我正在尝试通过等于某个值的子项查询 Firebase,但在特定的发布键处启动快照。

数据结构:

projectName
-posts
-postKey1
-storeId: 1
-postKey2
-storeId: 2
-postKey3
-storeId:3
-postKey4
-storeId:2
-postKey5
-storeId:3
-postKey6
-storeId:2

示例:

我正在尝试 queryOrderedByChild("storeId")queryEqualToValue("2") 但我希望快照返回时从“postKey4”开始按照顺序。

我当前的查询:

ref.queryOrderedByChild("storeId").queryEqualToValue("\(myId)").observeEventType(.Value, withBlock: {snapshot in 

我知道您不能在 queryStartingAtValuequeryEndingAtValuequeryEqualToValue 之后调用 queryEqualToValue:但我需要 queryEqualToValue 来获取我的 storeId。非常感谢任何帮助!

最佳答案

您可以将第二个参数传递给 queryStartingAtValue,指定开始的键。

ref.queryOrderedByChild("storeId")
.queryStartingAtValue(2, childKey: "postKey4")
.queryEndingAtValue(2)
.observeEventType(.Value, withBlock: {snapshot in
for childSnapshot in snapshot.children {
print(childSnapshot.key!!
}
})

这打印:

postKey4

postKey6

我必须承认这是我第一次使用 queryStartingAtValue 的第二个参数,所以我可能还没有完全理解它。

您不能使用 queryEqualToValue 的原因是它只会返回一个键,这不是您想要的。

关于ios - Firebase QueryOrderedByChild 以及 EqualToValue 和 StartingAtValue 组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38933148/

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