I have a very simple application that initiates a search and filter based on the query parameters. When I initiate the query https://example.com/?filter=2134
it initiates the search and shows me the result of schools. This means that the searchSchools()
function is being executed and the results are being fetched.
However, then I execute the filterSuggestions()
function, it doesn't seem to apply the filter.
However, when I do a console.log(suggestedSchools)
within mounted, it returns empty.
const app = new Vue({
el: '#app',
data: {
suggestedSchools : [],
filter : '',
filteredSchools : [],
},
mounted: function () {
// checking some get parameters and conditions and triggering the search
this.searchSchools(); // function that initiates ajax request and store the results into suggestedSchools
this.filter = 2134; // the postcode value comes from the get request
this.filterSuggestions(); // function that applies the postcode filter to the suggestedSchools list and assign the filtered results to filteredSchools.
},
methods: {
searchSchools() {
axios.get('/search-school').then(response => {
this.suggestedSchools = response.data;
this.filteredSchools = response.data;
})
},
filterSuggestions()
{
this.filteredSchools = this.suggestedSchools.filter(school => {
// filtering logic
}
},
},
});