Looking to implement a list filtering system using checkboxes.
This is how I am looping through an array from VUEX:
<div class="checkbox" v-for="brand in brands" :key="brand.id">
<input name="brands" type="checkbox" :value="brand.name" v-model="checkedBrand" />
<label for="brands">{{brand.name}}</label>
</div>
Here is the function I am using:
filteredList() {
if (this.checkedBrand.length > 0) {
return this.shoes.filter(shoe => {
return shoe.brand.match(
new RegExp(
this.checkedBrand.forEach(check => {
return +check + "|";
}),
"g"
)
);
});
} else {
return this.shoes;
}
}
I currently have the line: When it's new RegExp(checkedBrand[0]+'|'+checkedBrand[1], 'g'), but I want to avoid hardcoding that.