-
-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
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
[
{ name: 'Simon', children: [{ name: 'Simon' }] },
]
Which is what I want
filter('Fred') returns
[
{ 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?
sladg
Metadata
Metadata
Assignees
Labels
No labels