我正在尝试使用queryEqual(toValue:在swift中。我遇到的问题是我得到了null。
我的数据如下所示
"time" : {
"149791341619654" : {
"URL_ID" : "02D03DA8-A652-4EFA-946F-1F0F2A963449",
"UUID" : "F496B98E-3B4E-4602-B06D-C09B7F42DCB5",
"date" : 1.497913416196546E9,
"huer" : 0,
"latitude" : 32.87926715336076,
"longitude" : -117.2139702738423,
"type_" : "Image",
"uid" : "BjN8usKaW7NhqD2DxPPqAkjhnSx2"
},
"149791381894099" : {
"URL_ID" : "AB8D20E9-D1EB-4FD0-B0A8-CE755D1D8B91",
"UUID" : "F534E1FC-DC55-4AFB-847D-64B614EF7137",
"date" : 1.497913818940991E9,
"huer" : 0,
"latitude" : 32.87926715336076,
"longitude" : -117.2139702738423,
"type_" : "Image",
"uid" : "BjN8usKaW7NhqD2DxPPqAkjhnSx2"
},
"149791881234864" : {
"URL_ID" : "A3207072-FC64-4A09-87C0-E1340051B140",
"UUID" : "D0C3FA34-2790-4896-96F7-E0E7C3E17687",
"date" : 1.497918812348642E9,
"huer" : 0,
"latitude" : 32.87915823052905,
"longitude" : -117.2140478064466,
"type_" : "Video",
"uid" : "BjN8usKaW7NhqD2DxPPqAkjhnSx2"
}
}
我希望能够只得到孩子" 149791381894099"例如。 我目前使用的swift中的代码是(抱歉格式化很奇怪)
self.rootRef.child(uidOtherProfile).child("time").queryEqual(toValue: 149791381894099).observeSingleEvent(of: .value, with: { (snapshot) in})
但我用过
self.rootRef.child(uidOtherProfile).child("time").queryEqual(toValue: "149791381894099").observeSingleEvent(of: .value, with: { (snapshot) in
答案 0 :(得分:0)
Firebase的默认排序顺序是优先级。要查询您需要致电queryOrderedByKey()
的按键:
ref.queryOrderedByKey().queryEqual(toValue: "149791381894099").observe(.childAdded, with: { (snapshot) in
print(snapshot)
})