【发布时间】:2017-01-19 11:01:19
【问题描述】:
我的 firebase json 树是这样的
{
"-KZVOY6qU29fJlRSwRNo" : {
"fedStateDetails" : "Fasted",
"targetkcal" : 596,
"timestamp" : 1.482307285673975E9,
"userid" : "816",
"workout_id" : "123"
},
"-KZVSmeW94XetROs0nsN" : {
"fedStateDetails" : "Fasted",
"targetkcal" : 1874,
"timestamp" : 1.482308270356936E9,
"userid" : "47",
"workout_id" : "129"
},
"-KZWGdx-j1q7J37x0wck" : {
"fedStateDetails" : "Fasted",
"targetkcal" : 0,
"timestamp" : 1.482321866382767E9,
"userid" : "47",
"workout_id" : "40"
}
}
所以我只需要获取“userid”为 47 且“timestamp”在给定范围之间的用户,我的代码如下所示。
let startTime = Date().timeIntervalSince1970 - 10800.0
let endTime = Date().timeIntervalSince1970
self.dbRef.child(FireBaseTable.workOutInfoTable)
.queryOrdered(byChild: "timestamp")
.queryStarting(atValue: startTime, childKey: "timestamp")
.queryEnding(atValue: endTime, childKey: "timestamp")
.queryEqual(toValue: "47")
.observe(.value) { (snapshot1 :FIRDataSnapshot?) in
if let value : Dictionary<String,AnyObject> = snapshot1?.value as? Dictionary<String,AnyObject>
{
print("*********")
print(value)
}
}
但我不能同时应用两个 order by。请帮忙。 提前致谢。
【问题讨论】:
-
不,不可能在 firebase 中同时添加 2 个订单...在获取数据后,您必须通过其他方式对其进行排序
-
@EICaptainv2.0 是的,我知道,但如何获得预期的结果?有什么建议吗?会很有帮助的。
标签: ios swift xcode firebase firebase-realtime-database