Answer the question
In order to leave comments, you need to log in
How to write a filter?
Help write a filter that works like this - there is an array with filters that the selected objects must match.
The array consists of objects that contain flags by which to filter:activeFilter = ['display', 'water', 'gps']
{
disColor : true,
water : false,
gps : true
}
Answer the question
In order to leave comments, you need to log in
Let's add a description of the filters to the component. This will be an array of objects containing two properties: name (matches the property name in the elements of the filtered array) and activity (indicates whether this filter should be applied):
data: () => ({
filters: [
{ name: 'disColor', active: true },
{ name: 'water', active: true },
{ name: 'gps', active: true },
],
...
<label v-for="f in filters">
<input type="checkbox" v-model="f.active">
{{ f.name }}
</label>
computed: {
filteredItems() {
const filters = this.filters.filter(n => n.active);
return this.items.filter(n => filters.some(f => n[f.name]));
},
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question