Basically what am I doing wrong? This is a chained filter under computed.
Error is 'product.topic.sort' is not a function.
I am trying to use 'select' to have a sort option of ascending, descending, price high & price low.
V-model binds value to the js.
Under filters I'm trying to add a filter that does this sorting based on 'value'
if value = undefined, do nothing.
If value = Az, Ascending
if value = Za, Descending
if value = Ph, Price High
if value = Pl, Price low
Edit
Under filteredSearch() { I have other filters such as
.filter(product => this.filters.some(filter => product.topic.match(filter))) ||
this.products
.filter(p => p.topic.toLowerCase().match(this.search.toLowerCase()))
.filter(p => p.price <= this.priceFilter)
I want to ensure that all the other filters work with the sort filter.
HTML
<div id="app">
<h4>Sort</h4>
<select v-model="value">
<option value="Az">Ascending</option>
<option value="Za">Descending</option>
<option value="Ph">Price High</option>
<option value="Pl">Price Low</option>
</select>
<div class="block" v-for="product in filteredSearch">
<h3>{{product.topic}}</h3>
<p>{{product.price}}</p>
</div>
</div>
JS
var app = new Vue({
el: '#app',
data: {
products: [{
"topic": "english",
"price": "20"
},
{
"topic": "french",
"price": "60"
},
{
"topic": "science",
"price": "80"
}
],
value: "",
})
computed: {
filteredSearch() {
return this.products
.filter((product) => {
if (!this.value)
return true;
if (this.value == "Az") {
return product.topic.sort(function(a, b) {
a.topic - b.topic
});
}
})
}
}
});
if (product.topic)