I have an application that I use to import a CSV file which then converts it to JSON.
The JSON output looks like this
{
"Class": "Gecultiveerde paddestoelen",
"Soort": "Shii-take",
"Sortering": "Medium",
"LvH": "SP",
"Omschrijving": "SHIITAKE MEDIM STEMLESS unclosed",
"Trade unit composition": "8 x 150gr",
"Punnet type": "CARTON",
"CONTAINER BOX": "Multicrate (30x40x11)",
"Price (/box)": "10",
"Amount (container box) per Pallet / Europallet \r": "200 / 160\r"
}
Console log output
I need to groupBy on Class > Soort > Sortering which I don't know how to do in VUE/JS.
I am able to groupBy single colls like this
In the methods:
groupBy: function (array, key){
const result = {};
array.forEach(item => {
if (!result[item[key]]){
result[item[key]] = []
}
result[item[key]].push(item)
});
return result
},
Computed:
groups() {
return this.groupBy(this.parse_csv, 'Class');
},
In SQL this is very easy to do like this DBFiddle (the dbfiddle has all of the JSON data in it)
The expected output would be like
After obviously doing my fair share of googling and researching I have stumbled upon this answer. However I am not able to get this working in VUE as this is plain JS, this most likely is a mistake on my behalf for not being very familiar with js, but I would love some extra take on this.