How To Search Both Parent And Child Object In Javascript/lodash/es6?
So I'm using Vue to filter a list. This consists of the following structure (Baum Hierarchy if anyone is interested): [ { 'id': 61, 'created_at': '2016-11-23 22:07:10',
Solution 1:
you can do it with recursive function
var res = _.reduce(this.sortable, function reducer(result, item) {
if (item.name.search(new RegExp(search, "i")) !== -1) {
result.items = _.concat(result.items, result.parent || item);
}
result.items = _.concat(
result.items,
_.reduce(item.children, reducer, {parent: item, items: []}).items
)
return result;
}, {items: []}).items;
Post a Comment for "How To Search Both Parent And Child Object In Javascript/lodash/es6?"