I want to create a datasource dynamically for my table from a array of objects.
Required datasource value:
values = [
{
name: "Super Admin"
cv: 1
assessment1_title: score/status
assessment2_title: score/status
interview1_title: score/status
interview2_title: score/status
}
]
I have the following array of object:
data = {
"assessments": [
{
"id": 6,
"title": "PHP Laravel Developer",
"type": "Objective"
},
{
"id": 7,
"title": "Laravel Developer",
"type": "Objective"
}
],
"candidates": [
{
"id": 11,
"user_id": 1,
"user_name": "Super Admin",
"assessments": [
{
"id": 1,
"score": 5,
"duration": 1170,
"status": {
"id": 22,
"name": "completed"
}
},
{
"id": 2,
"score": 0,
"duration": 0,
"status": {
"id": 22,
"name": "Pending"
}
}
]
}
]
}
where the value of assessment_title will be dynamically generated from data.assessments.map(({title}) => title) and the value will be one of score and status
data.canditates.map(res => res.assessments.map(res2=> {
if res2.status.id ==22 {
value = res2.score
} else {
value = res2.status.name
}
})
);
I want to make the required datasource value. Thanks in advance
if res2.status.id ==22aren't you getting syntax error here ?data.canditates.map(res => res.assessments.map(....))will return an array of arrays, if you want a single level array, use.reduce()instead.