I am trying to filter some content rendered with Vue.js , but only the first filter is working, the size filter.
var vm = new Vue({
el: "#full_area",
data: {
projects: <?php print json_encode($postsa);?>,
selectedSize: "All",
selectedPlatform: "All"
},
computed: {
filteredProjects: function () {
var vm = this;
var size = vm.selectedSize;
var platform = vm.selectedPlatform;
if (size === "All") {
return vm.projects;
} else if (size != "All") {
return vm.projects.filter(function (project) {
return project.size === size;
});
}
if (platform === "All") {
return vm.projects;
} else if (platform != "All") {
return vm.projects.filter(function (project) {
return project.platform === platform;
});
}
}
}
});
<div class="filter">
<select name="selectedSize" v-model="selectedSize">
<option value="All">Website Size</option>
<option>1 Page</option>
...
<option>10+ Page</option>
</select>
</div>
<div class="filter">
<select name="selectedPlatform" v-model="selectedPlatform">
<option value="All">CMS Platform</option>
<option>Wordpress</option>
.....
</select>
</div>
I have tried several thing playing with the if`s and else, but no luck. Have any idea ?
Thanks.
return-ing. Which ends the execution of the function. If you want to return the result of multiple filters, you have to hold the results of the previous filter in the result, filter by all subsequent filters and at the end return the final result.