gpt4 book ai didi

ios - 火力地堡 swift : queryEqualToValue by childKey is not working

转载 作者:IT王子 更新时间:2023-10-29 05:30:35 24 4
gpt4 key购买 nike

有没有人有幸使用这个函数:

.queryEqualToValue(value: AnyObject?, childKey: String?)

两件事:

1)childKey好像不允许深度路径,直接children就可以了

2) 我根本无法让它工作!鉴于我的结构:

"post": {
"groupName": "hello world"
}

如果我做一个简单的:

postRef.queryEqualToValue("hello world", childKey: "groupName").observeSingleEvent( ... )

它根本不返回任何帖子。相反,我必须采取以下迂回方式:

postRef.queryOrderedByChild("groupName").queryEqualToValue("hello world").observeSingleEvent( ... )

让它发挥作用!

我是否错误地使用了上述功能?

最佳答案

Firebase 文档中写了以下内容:

queryEqualToValue Return items equal to the specified key, value, or priority, depending on the order-by method chosen.

Retrieve Data on iOS

重要的部分是:“取决于选择的排序方法。”

因此请务必将 queryEqualToValue-方法与 orderBy-方法结合使用。

例如:

    let groupState = "open"

ref.child("groups").queryOrdered(byChild:"state").queryEqual(toValue:groupState).observe(enventType: .value, with: { snapshot in
// Returns all groups with state "open"
for group in snapshot.children {
print(group)
}
})

PS:新的 Firebase iOS 指南中没有提到带有 childKey 的变体。

关于ios - 火力地堡 swift : queryEqualToValue by childKey is not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37577138/

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