我有数据库"通知"。
{
"Notification": {
"user_id":
"date":
"type":
"info": {
"who_id":
"whom_id":
}
}
}
当我第一次启动应用程序时,我会获取并获取来自" Notification"的所有数据。当我向" Notification"添加新数据时,我获得没有字段" info"的数据。只有字段:date,type,user_id。
我的代码:
func fetchNotitfications() {
FIRDatabase.database().reference().child("Notification").queryOrdered(byChild: "user_id").queryEqual(toValue: FIRAuth.auth()?.currentUser?.uid).observe(.childAdded, with: { (snapshot) in
if let notificationDict = snapshot.value as? [String:AnyObject] {
let notification = Notification()
notification.setValuesForKeys(notificationDict)
self.notificationTableView.arrayNotification.append(notification)
self.notificationTableView.reloadData()
}
})
}
答案 0 :(得分:0)
使用childadded时,快照的返回方式与预期不同。
而不是得到`
"Notification": {
"user_id":
"date":
"type":
"info": {
"who_id":
"whom_id":
}
}
根据查询过滤数据的方式,您很可能获得以下内容。
["user_id":
"date":
"type":
"info": {
"who_id":
"whom_id":
}
]