I'm struggling with implementing filters using checkboxes on a list of results and could really use some assistance.
Currently, only the 'All' option is working for applying any filtering logic.
Here is how my HTML looks like with the filters and loop:
<div class="container" id="clubs">
<div class="filter">
<label><input type="checkbox" v-model="selectedCategory" value="All" /> All</label>
<label><input type="checkbox" v-model="selectedCategory" value="Parking" /> Parking</label>
<label><input type="checkbox" v-model="selectedCategory" value="Toilets" /> Toilets</label>
<label><input type="checkbox" v-model="selectedCategory" value="Floodlights" /> Floodlights</label>
</div>
<ul class="clubs-list">
<li v-for="club in filteredClubs">{{ club.clubName }}</li>
</ul>
</div>
And here's the code inside my VueJS app:
var vm = new Vue({
el: "#clubs",
data: {
clubs: [
{ clubName: "Club One", clubParking: true, clubToilets: false, clubFloodlights: true },
{ clubName: "Club Two", clubParking: true, clubToilets: false, clubFloodlights: false },
{ clubName: "Club Three", clubParking: false, clubToilets: true, clubFloodlights: true },
],
selectedCategory: "All"
},
computed: {
filteredClubs: function() {
var vm = this;
var category = vm.selectedCategory;
if(category === "All") {
return vm.clubs;
} else {
return vm.clubs.filter(function(club) {
return club.clubParking === category;
});
}
}
}
});
I'd appreciate any help as I've been stuck on this issue for hours.