My goal is to populate the predefined data property that I have set.
reportGroupData: [
{
program_name: "",
iteration_name: "",
report_template_name: "",
toggle: true,
report_details: [],
},
]
This portion of code shows how I am trying to utilize my API in order to populate the predefined data property. It's worth mentioning that async is being used in this process.
api.get(`get-coach-reports/${this.userData.ind_id}`).then((res) => {
this.reportData = res.data;
this.reportGroupData.forEach(element => {
this.reportData.forEach((mapElement)=>{
element.program_name = mapElement.program_name
element.iteration_name = mapElement.iteration_name
element.report_template_name = mapElement.report_template_name
element.report_details.push(this.reportData)
})
});
The information retrieved from my API, res.data
, looks like this:
[
{
"full_name": "Arnd Philipp Von Frese Von Issendorff",
"report_file": "5Step.html",
"report_template_name": "Five STeP Profile Coach Report",
"suborg_name": "Masters Degrees",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023"
},
...
]
My objective is to structure the data in a specific way, as shown here:
[
{
"report_template_name": "Five STeP Profile Coach Report",
"program_name": "Masters in Financial Analysis (MFA)",
"iteration_name": "MFA2023",
"toggle": true,
"report_details":[
{
"full_name": "Arnd Philipp Von Frese Von Issendorff",
...
},
...
]
},
...
]
In my console output, I can see that the report_details
are successfully populated inside reportGroupData
.
https://i.sstatic.net/2XIIv.png
I have also explored a solution on Stack Overflow for restructuring arrays, but encountered errors with spread/rest operators within forEach or map functions. Could this be due to using Vue instead of plain JavaScript?