【发布时间】:2020-08-19 00:04:36
【问题描述】:
我无法将以下数组 data1 转换为看起来像 data2:我尝试使用 lodash 但它有点奇怪 _gropuby 给了我一个对象数组。我应该在数组内部循环...为此创建一个自定义函数。或者 lodash 中是否有一个技巧来简化这一点。谢谢 /************************************************* *************************************************
let data1 = [{
KlasCode: "AA",
LESDatum: "06/02/2017",
LESID: "1",
ModuleID: "1061",
ParticipationLetterCode: "Y"
}, {
KlasCode: "AA",
LESDatum: "07/02/2017",
LESID: "2",
ModuleID: "1061",
ParticipationLetterCode: "X",
},
{
KlasCode: "AA",
LESDatum: "13/02/2017",
LESID: "3",
ModuleID: "1062",
ParticipationLetterCode: "Z"
},
{
KlasCode: "BB",
LESDatum: "16/02/2017",
LESID: "4",
ModuleID: "1063",
ParticipationLetterCode: "X"
}
]
//The output should be like a tree array system, something more organized such as the following code :
let data2 = [{
KlasCode: "AA",
Modules: [
{
ModuleID: "1061",
Participation: [{
ParticipationLetterCode: "Y",
LESDatum: "06/02/2017",
LESID: "1"
},
{
ParticipationLetterCode: "X",
LESDatum: "07/02/2017",
LESID: "2"
}
},
{
ModuleID: "1062",
Participation:[{
ParticipationLetterCode: "Z",
LESDatum: "13/02/2017",
LESID: "3"
}]
}
}]
},
{
KlasCode: "BB",
Modules: [{
ModuleID: "1063",
Participation: [{
ParticipationLetterCode: "x",
LESDatum: "6/02/2017",
LESID: "4"
}]
}]
}
]
【问题讨论】:
-
应该是 AA 抱歉,我更新了东西 thx。我试图结合 .map() 和 _gropuby。没有运气
-
这有帮助吗?
标签: javascript arrays vue.js lodash syncfusion