So I have the following scenario:
I have multiple toggles.
If a switch is toggled on, show all items of the same type.
If off, don’t show it.
I have the following code:
let filter = wixData.filter();
let query = wixData.query("SHOP");
// Toggle value
let lagerVal = $w("#lagerToggle").value;
let paleVal = $w("#paleAleToggle").value;
let lagerQuery;
let paleQuery;
// Lager
if ($w("#lagerToggle").checked) {
lagerQuery = query.eq("type", lagerVal);
} else {
lagerQuery = query.ne("type", lagerVal);
}
// Pale Ales
if ($w("#paleAleToggle").checked) {
paleQuery = query.eq("type", paleVal);
} else {
paleQuery = query.ne("type", paleVal);
}
finalQuery = lagerQuery.and(paleQuery);
finalQuery
.find()
.then(results => {
$w("#shopListing").data = results.items;
//console.log(results.query);
//console.log(results.items);
})
.catch(err => console.log(err));
The problem is when I run this the query returns 0 items unless only one toggle is checked. I can’t figure out what the problem is. Am I using the and() function wrong or is it not what I think it is?
What I want to achieve is something like this in SQL:
SELECT * FROM table WHERE type = “type1” AND type = “type3” and so on…
Any help would be appreciated. Thanks.