For this particular project, I am utilizing Vuejs Typescript with a data structure that looks like this:
["order":
{
"id":1,
"created_at":"2019-12-06T10:22:17Z",
"status":"open",
"updated_at":"2020-07-27T04:21:06Z",
"recipient":null,
"custom_fields":[
{"id":2,"value":'ABC'},
{"id":3,"value":'EFG},
{"id":4,"value":'CSA'}
]
}
]
The function I use to retrieve the data is as follows:
private mapUnprinted (data: any) : IUnprintedSet {
const result: IUnprintedSet = { orders: [], pagination: {} }
if (data) {
data.forEach((anUnprinted: any) => {
const order: IUnprinted = {
id: anUnprinted.id,
created_at: anUnprinted.created_at,
status: anUnprinted.status,
updated_at: anUnprinted.updated_at,
recipient: anUnprinted.recipient,
custom_fields: anUnprinted.custom_fields
// filter((item: any) => item.custom_fields.id === '3'),
}
result.orders!.push(order);
})
result.pagination = {
currentPage: data.pagination ? data.pagination.currentPage : undefined,
pageSize: data.pagination ? data.pagination.pageSize : undefined,
totalPages: data.pagination ? data.pagination.totalPages : undefined,
totalResults: data.pagination? data.pagination.totalResults : result.orders!.length
}
}
return result
}
I included the line:
filter((item: any) => item.custom_fields.id === '3'),
However, it appears that this code snippet does not work correctly and returns an empty array. The main issue lies in my attempt to extract the value from custom_fields where the ID is equal to 3.
This is how I tried to retrieve the custom_fields:
anUnprinted.custom_fields.filter((item: any) => item.id === '3'),
"order": {
"id": 1,
"created_at": "2019-12-06T10:22:17Z",
"status": "open",
"updated_at": "2020-07-27T04:21:06Z",
"recipient": null,
"custom_fields": []