R
R
Ruslan Absalyamov2018-10-27 21:30:14
Vue.js
Ruslan Absalyamov, 2018-10-27 21:30:14

How can I filter data by multiple values?

Everything works for me if there is one filtering, but if several are done, then which upper filtering does it prevail over the lower one, how can I roughly make it take into account the data that comes from two filters?
https://codesandbox.io/s/pyvjxxnnvj
The code where the data is filtered is in App.vue:212 in the computed employeeList

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Zharov, 2018-10-27
@rusline18

employeeList: function() {
  return this.items.filter(item => 
    Object.keys(this.filterItems).reduce((acc, filterKey) => {
      let filterCondition = this.filterItems[filterKey];
      return acc && !!~item[filterKey].indexOf(filterCondition);
    }, true)
  ).sort(....);
}

in the predicate, we fold filterItems, if at least one of its properties does not satisfy the condition !!~item[filterKey].indexOf(filterCondition), the predicate will return false and the element will be filtered

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question