everybody. I have data coming to Vue app from WP back-end via WP-API. They are gathered in object 'Bookers'. I have some fields to display in each item (booker). For example Paying Systems: Visa, Mastercard, Bitcoin Cash, etc. (They are stored in bookers.acf.pay_systems) And I want to have an opportunity to filter "Bookers" items based on user input. User choose "Visa" and "Mastercard" - and I want to leave only items bookers which have Paying Systems: Visa and Mastercard. Ordinary behavior. So I have check-boxes set to take user input:
<label><input class="paysys-check" type="checkbox" value="Visa" id="visa-check" v-model="visaCheck" /> Visa</label>\
<label><input class="paysys-check" type="checkbox" value="Mastercard" id="mastercard-check" v-model="mastercardCheck" /> Mastercard</label>\
I have data:
data: {
bookers: [], //data coming from WP-API
paysysValues: [], // array to store user input
visaCheck: false, mastercardCheck: false, appleCheck: false, googleCheck: false,bitcoinCheck:
false,kievstarCheck: false, privat24Check: false, // to catch user input event, if all are false filters are clear and we display original data
}
Displaying data:
<div class="booker-card-wrap" v-for="booker in filteredBookers"> {{booker}} <div>\
And I have computed property to display filtered/unfiltered data:
computed: {
filteredBookers: function () {
//find all checked paying systems and pass them to paysysValues array
var paysysChecks = document.querySelectorAll('.paysys-check');
for (var i = 0; i < paysysChecks.length; i++) {
if (paysysChecks[i].checked) {
this.paysysValues.push(paysysChecks[i].value);
}
}
// checking user input event to update calculated property via reactive behavior
if ( !this.visaCheck & !this.mastercardCheck & !this.appleCheck & !this.googleCheck & !this.bitcoinCheck & !this.kievstarCheck & !this.privat24Check) {
return this.bookers
} else {
// and here I'm trying to compare user input array (paysysValues) with paying systems set
// for each booker and filter data only if we have intersection
return this.bookers.filter(function (item) {
return item.acf.pay_systems.filter(x => this.paysysValues.includes(x));
})
}
}
},
And if I use to filter condition some particular value, for example item.acf.pay_systems.filter[0] == 'Visa' everything work well. But then I try to use intersection of two array it doesn't work.
So, guys, please tell me what am I doing wrong