作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试通过等于某个值的子项查询 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
我知道您不能在 queryStartingAtValue
、queryEndingAtValue
或 queryEqualToValue
之后调用 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/
我正在尝试通过等于某个值的子项查询 Firebase,但在特定的发布键处启动快照。 数据结构: projectName -posts -postKey1 -storeId: 1
我是一名优秀的程序员,十分优秀!