This commit is contained in:
Timo Hocker 2020-06-29 14:23:24 +02:00
parent 3cca634101
commit 94f7ec85e9

View File

@ -78,6 +78,14 @@ function is_nil (obj) {
|| (typeof obj === 'number' && isNaN (obj)); || (typeof obj === 'number' && isNaN (obj));
} }
function to_search_string (element, field) {
return Array.isArray (field)
? field.map ((f) => element[f])
.filter ((v) => typeof v !== 'undefined')
.join (' ')
: element[field];
}
/** /**
* filter nested objects * filter nested objects
* *
@ -93,14 +101,7 @@ function recursive_filter (input, filters, children_key = 'children') {
data[i] = e; data[i] = e;
let match = true; let match = true;
for (const filter of filters) { for (const filter of filters) {
const is_multi_filter const search_str = to_search_string(e, filter.field);
= Array.isArray (filter.fields);
const search_str = is_multi_filter
? filter.fields.map ((f) => e[f])
.filter ((v) => typeof v !== 'undefined')
.join (' ')
: e[filter.field];
if (!filter.filter.test (search_str)) { if (!filter.filter.test (search_str)) {
match = false; match = false;