我一直在尝试使用他们的指南查询我的firebase数据库,但我无法正确返回结果。 如果有人能指出我做错了什么或纠正了我,那将会非常有帮助。
以下是我的代码段
let ref = DataService.dataService.BASE_REF
let myQuery = (ref.child("testing")).queryOrderedByKey()
let MyQuery1 = (ref.child("testing")).queryOrderedByValue()
let MyQuery2 = (ref.child("testing")).queryEqualToValue("Alphaa")
let MyQuery3 = (ref.child("testing")).queryEqualToValue("Alphaa", childKey: "Alpha")
myQuery.observeSingleEventOfType(.Value, withBlock: {
snapshot in
print("Ordered By Key")
print(snapshot.value)
})
MyQuery1.observeSingleEventOfType(.Value, withBlock: {
snapshot in
print("Ordered by Value")
print(snapshot.value)
})
MyQuery2.observeSingleEventOfType(.Value, withBlock: {
snapshot in
print("Value Equal")
print(snapshot.value)
})
MyQuery3.observeSingleEventOfType(.Value, withBlock: {
snapshot in
print("Ordered by Value & Key")
print(snapshot.value)
})
这是结果屏幕 按键和值排序都不会将其排序。
Optional({
Alpha = Gammaa;
Alright = 24;
Beta = Betaa;
Delta = Deltaa;
Epsilon = Epsilonn;
Eta = Etaa;
Gamma = Alphaa;
Iota = Iotaa;
Lets = 3;
Okay = 1;
Theta = Thetaa;
Zeta = Zetaa;
beep = 4;
boop = 11;
})
价值平等和价值与价值订购键给我可选(null)
JSON表值
"testing" : {
"Alpha" : "Gammaa",
"Alright" : 24,
"Beta" : "Betaa",
"Delta" : "Deltaa",
"Epsilon" : "Epsilonn",
"Eta" : "Etaa",
"Gamma" : "Alphaa",
"Iota" : "Iotaa",
"Lets" : 3,
"Okay" : 1,
"Theta" : "Thetaa",
"Zeta" : "Zetaa",
"beep" : 4,
"boop" : 11
}
我正在尝试返回相等的值,或者从服务器端而不是客户端对其进行排序。
答案 0 :(得分:1)
我继续测试并改变了我的结果
MyQuery1.observeSingleEventOfType(.Value, withBlock: {
snapshot in
print("************")
print("Ordered by Value")
for snap in snapshot.children {
print(snap);
}
})
这给了我想要的价值结果:D和钥匙
Ordered by Value
Snap (Okay) 1
Snap (Lets) 3
Snap (beep) 4
Snap (boop) 11
Snap (Alright) 24
Snap (Gamma) Alphaa
Snap (Beta) Betaa
Snap (Delta) Deltaa
Snap (Epsilon) Epsilonn
Snap (Eta) Etaa
Snap (Alpha) Gammaa
Snap (Iota) Iotaa
Snap (Theta) Thetaa
Snap (Zeta) Zetaa