I have a program that I utilize to import a CSV data file and then convert it into JSON format.
The resulting JSON structure is as follows:
{
"Class": "Cultivated Mushrooms",
"Type": "Shii-take",
"Grade": "Medium",
"LvH": "SP",
"Description": "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"
}
Output in the console log:
https://i.sstatic.net/X3Gg4.png
I need to group the data by Category > Type > Grade, but I am unsure how to achieve this using VUE/JS.
I can successfully group the data by individual fields like so
In the methods section:
groupBy: function (array, key){
const result = {};
array.forEach(item => {
if (!result[item[key]]){
result[item[key]] = []
}
result[item[key]].push(item)
});
return result
},
Computed property:
groups() {
return this.groupBy(this.parse_csv, 'Class');
},
This grouping operation is quite straightforward in SQL, demonstrated here on DBFiddle (the example includes all the JSON data).
The desired outcome should resemble https://i.sstatic.net/1cn3U.png
Despite thorough research and attempts, I came across this informative response. However, I am struggling to adapt this solution into VUE due to my limited knowledge of JavaScript. Any additional insight would be greatly appreciated.