I get an array through a PHP backend, which shows like below :
{
"response":{
"code":"0000",
"message":"OK"
},
"data":[
{
"id":"2",
"description":"Description 1",
"image":"work\/(1)(1).jpg",
"job_id":"5",
"final_upload":"N"
},
{
"id":"4",
"description":"Description 2",
"image":"work.jpg",
"job_id":"5",
"final_upload":"Y"
}
]
}
On my page i have an ng-repeat list of user ID's , I need to map the user ID to the job_id element in the array that i receive above. So that the image and description related to that job_id will show.
As shown above , there's 2 job_id elements with value "5".
I receive the array above by resolving it as workList.
With the following function i pass in the user_id and map it to the workList array and attempt to retrieve the image and descriptions related to that ID.
$scope.viewWork = function(id) {
var uid = id;
$scope.works = workList.map(item =>
({
image: workList.find(work => work.job_id === uid).image,
description: workList.find(work => work.job_id === uid).description,
}));
}
The ID posts fine , and then I have an ng-repeat element to display the results...
<tr ng-repeat="works in works">
<td>{{ works.image }}</td>
<td>{{ works.description }}</td>
</tr>
But what i receive is always only the first matching element. The second result is a duplicate of the first. But I do receive 2 results , which is what it should be, But the issue is both of them are the same and not showing the actual second result..
I'm trying to get both matching image and description values for the job_id == 5, But it only returns the first matching element twice....
Thanks for any help .
worklist.filter((el) => el.job_id === uid).map((item) => ... )
– daniel0mullins yesterday