我需要将收到的“原始” Firestore数据分组为可用于适当显示的数组格式。
我从Firestore收到了此邮件:
{
activityName: "BFG",
comment: "Roger is naughty",
mark: 86,
subject: "English",
task: "reading",
term:1,
year: 2019
}, {
activityName: "The Twits",
comment: "Roger is really good",
mark: 99,
subject: "English",
task: "reading",
term:2,
year: 2019
},
{
activityName: "Basic sums",
comment: "Roger is average",
mark: 19,
subject: "Maths",
task: "Addition",
term:2,
year: 2019
}
并且我希望以手风琴形式将其作为分组数据呈现
年份->任期->主题->任务-> activityName->标记(和注释)
因此,我认为最好/最简单的方法是将数据转换为以下格式,以简化用于显示分组数据的循环。
{
year:2019,
terms: [
{term: 1,
subjects: [
{subject: "English",
tasks: [
{task: "reading",
activities: [
{activityName: "BFG",
result: [
{comment: "Roger is naughty",
mark: 86
}]
}]
}]
}]
},
{term: 2,
subjects: [
{subject: "English",
tasks: [
{task: "reading",
activities: [
{activityName: "The Twits",
result: [
{comment: "Roger is really good",
mark: 99
}]
}]
}]
}]
},
{term: 2,
subjects: [
{subject: "Maths",
tasks: [
{task: "Addition",
activities: [
{activityName: "Basic sums",
result: [
{comment: "Roger is average",
mark: 19
}]
}]
}]
}]
}
]
}
为使这种新结构发生而对循环或想法的任何建议将不胜感激。