Answer the question
In order to leave comments, you need to log in
How to filter multidimensional array in vue js?
How to properly filter a multidimensional array of this type:
[ { "title": "Запрашиваемый код детали",
"brands": [ {
"code": "123456",
"name": "FILTR",
"description": "Фильтр масляный",
"positions": [ {
"price": "221 ₽",
"availability": "8 шт."
},{
"price": "236 ₽",
"availability": "2 шт."
} ],
} ],
} ],
props:{
groups: Array,
},
computed: {
filtered() {
let filters = this.filters;
return this.groups.filter((group) => {
let brands = group.brands.filter((brand) => {
if (!filters['brands'].value.includes(brand.name) && filters['brands'].value !== [] && !brand.positions) return false;
let positions = brand.positions.filter(function (position) {
Object.keys(filters).forEach((index) => {
if (index !== 'brands'){
if (!filters[index].value[0] <= parseInt(position[index]) || !filters[index].value[1] >= parseInt(position[index])) {
return false;
}
}
});
return true;
});
return positions !== [];
});
return brands !== [];
});
},
filters() { return this.$store.state.search.filters },
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question