我想知道是否有人对如何在'Firebase'中一次查询数组中的多个字符串有任何想法。基本上查询就像使用 AND 条件一样。我已经研究过以一百种不同的方式重构我的数据,但没有任何方法对我有用。另外,我有太多的数据要转储所有数据,然后在执行查询后匹配我的数组。非常感谢任何帮助或建议。
var uniqueStoreId = [“1”, “2”, “3”, “4”, “5”, “6”]
var posts = [Post]()
ref.queryOrderedByChild("storeId").queryEqualToValue("\(uniqueStoreId)").observeEventType(.Value, withBlock: {snapshot in
if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshot{
if let postDict = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
let post = Post(postKey: key, postData: postDict)
self.posts.insert(post, atIndex: 0)
}
}
}
})
答案 0 :(得分:0)
//做这样的事情,检查它的数组或词典,然后加入一个数组然后根据要求使用..享受
var arrMessage = [MessageFirebase]()
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
//If its a Array then use below method
for snap in snapshots {
if let postDictionary = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
let message = MessageFirebase(key: key, dictionary: postDictionary)
// Items are returned chronologically, but it's more fun with the newest jokes first.
//if needed
arrMessage.insert(message, atIndex: 0)
}
}
//If its a dictionary then use below method
if !(arrMessage.count > 0) {
let key = snapshot.key
let message = MessageFirebase(key: key, dictionary: snapshot.value!)
// Items are returned chronologically, but it's more fun with the newest jokes first.
//if needed
arrMessage.insert(message, atIndex: 0)
}
}