我正在尝试访问键引用的数据对象。在这种情况下,我们将“申请人”数据嵌套在事件内。我正在尝试使用该数据创建一个新对象。我可以访问顶级事件数据和每个申请人的密钥,但是我不知道如何访问申请人数据,例如,申请日期,备注和状态。
我想说诸如applicationStatus = key.status之类的东西,但这不起作用。
onCreateApplication () {
fb.eventsCollection.orderBy('startDate', 'desc').onSnapshot(querySnapshot => {
let appsArray = []
querySnapshot.forEach(doc => {
let event = doc.data()
let eventId = doc.data().id
let eventTitle = doc.data().title
let eventSlug = doc.data().slug
let applications = doc.data().applicants
let appStatus = doc.data().applicants.status
for (var key in doc.data().applicants) {
let eventData = {
id: eventId,
title: eventTitle,
slug: eventSlug
}
let userData = {
id: key
}
let application = {
event: eventData,
user: userData,
status: key.status????????,
appliedDate: key.created??????
}
fb.applicationsCollection.add(application)
}
})
})
},
答案 0 :(得分:0)
这是我对您的数据结构进行的最佳猜测。希望对您有所帮助,请发表评论以澄清其他内容。
onCreateApplication(){
fb.eventsCollection.orderBy('startDate', 'desc').onSnapshot(querySnapshot => {
querySnapshot.forEach(doc => {
let data = doc.data();
let applications = Object.keys(data.applicants).map(function(id){
let application = {
event: {
id: data.id,
title: data.title,
slug: data.slug
},
user: {
id: id
},
status: data.applicants[id].status,
appliedDate: data.applicants[id].created
})
fb.applicationsCollection.add(application);
return application;
})
})
})
}