[英]Swift Firebase - Array of items based on UID
这是这里每个节点含义的简要概述:
我想做的是由当前用户查询此结构(相同的UID与上面的第二个项目符号匹配),然后按DueDate字符串对结果进行排序/排序,如图像中的属性所示。
如何才能做到这一点?
这是我现在用来尝试查询的代码,但是它没有打印出任何快照,表明做错了。
let reference = Firebase(url:"https://something.firebaseio.com/orders/")
reference.queryEqualToValue(reference.authData.uid).observeEventType(.Value, withBlock: { snapshot in
if (snapshot.exists()) {
print(snapshot.value)
}else{
print("No Snapshot?!")
}
})
QueryByValue将查看Firebase参考中所有键/值对的值。 您的情况下的uid是键,而不是值。 它的值将是快照中其下的对象的字典,并且它将不查询它,因为该字典不等于您的uid。 而是只需将引用的路径附加到uid,然后调用.observeEventType
let reference = Firebase(url:"https://something.firebaseio.com/orders/")
//This will make your url point to the current users uid within the orders endpoint
reference.childByAppendingPath("\(reference.authUser.uid)/")
reference.observeEventType(.Value, withBlock: { snapshot in
if (snapshot.exists()) {
print(snapshot.value)
//You should have a dictionary here now. Do a sort by valueForKey
}else{
print("No Snapshot?!")
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.