Obtaining an array of nested objects from a database is my current task.
Each object in the array includes a "metadataIdStrings" member that functions like a dictionary.
For instance:
[{
"customerId": 48,
"uploaderId": "markdolenc",
"filename": "1.pdf",
"createdOn": {
"$date": "2020-08-25T12:06:10.165Z"
},
"lastModified": {
"$date": "2020-08-28T06:16:40.352Z"
},
...
}]
I am tasked with filtering objects that have specific values within their "metadataIdStrings" based on a search field input.
The challenge lies in the fact that the keys in this dictionary do not remain consistent across all objects.
My initial approach was:
filteredList(){
var searchValue = this.search;
return this.correctDocuments.filter(doc => {
return Object.values(doc.metadataIdStrings).some(val => {
var includes = val.toLowerCase().includes(searchValue.toLowerCase())
return includes
})
})
}
However, I'm encountering issues as it does not work as expected. What could be the missing piece here?
EDIT:
Upon Peter's suggestion, I delved into debugging this.correctDocuments.filter
and found that it returns the correct items. The issue arose from binding data to this.search
inside a table, where it searches for filenames rather than intended fields.
Simple oversight on my part.