Open ziggy6792 opened 2 years ago
Hi
I want to use search an array and keep an item in the array if it or any of its children contain my search string
Example data
const data = [ { name: 'Simon', children: [{ name: 'Simon' }] }, { name: 'Ben', children: [{ name: 'Fred' }] }, ];
I tried with the following function
const filter = (searchString) => filterDeep( data, (value: any, key: string, parent: any) => { return value.toString().toLowerCase().includes(searchString.toLowerCase()); } );
filter('Simon') returns
filter('Simon')
[ { name: 'Simon', children: [{ name: 'Simon' }] }, ]
Which is what I want
filter('Fred') returns
filter('Fred')
[ { children: [{ name: 'Fred' }] }, ]
But I want
[ { name: 'Ben', children: [{ name: 'Fred' }] }, ]
When a child is found I want its parent/parents to be included in the result
Is this possible with deepdash?
Hi
I want to use search an array and keep an item in the array if it or any of its children contain my search string
Example data
I tried with the following function
filter('Simon')
returnsWhich is what I want
filter('Fred')
returnsBut I want
When a child is found I want its parent/parents to be included in the result
Is this possible with deepdash?