如何获取其中username = current user和isCompleted = false的帖子的值。
override func viewWillAppear(animated: Bool) {
// How can I make a query to get the post along with the current user and the isCompleted = false.
let postRef = FIRDatabase.database().reference().child("posts").queryOrderedByChild("username").queryEqualToValue(FIRAuth.auth()!.currentUser!.displayName!)
// If I write the query like below if it will through error
// let postRef = FIRDatabase.database().reference().child("posts").queryOrderedByChild("username").queryEqualToValue(FIRAuth.auth()!.currentUser!.displayName!).queryOrderedByChild("isCompleted").queryEqualToValue(false)
postRef.observeEventType(.Value, withBlock: { (snapshot) in
var newPosts = [TodoItemDatabase]()
for post in snapshot.children{
let post = TodoItemDatabase(snapshot: post as! FIRDataSnapshot)
newPosts.insert(post, atIndex: 0)
}
toDoList = newPosts
dispatch_async(dispatch_get_main_queue(), {
self.toDoListTable.reloadData()
})
}) { (error) in
print(error.localizedDescription)
}
}
以下是帖子的数据结构