更新时间:2023-02-02 22:50:49
在 eventAttendees/fm
下,您有多个孩子.因此,您也需要遍历代码中的那些子节点:
Under eventAttendees/fm
you have multiple children. So you will need to loop over those child nodes in your code too:
let ref = Database.database().reference()
ref.child("eventAttendees/fm").observe(.value, with: { (snapshot) in
for child in snapshot.children.allObjects as [FIRDataSnapshot] {
print (child.key)
ref.child("users/\(child.key)").observeSingleEvent(of: .value, with: { (userSnapshot) in
let content = userSnapshot.value as? [String : AnyObject] ?? [:]
print(content["name"])
})
}
})