Dear Wix community,
I have a dataset containing questions which have a field “categories”, where I can choose one or more categories that match the question. This is a reference to another dataset called “CategoryQuestions”.
Now on my page, I want to be able to filter questions by one category. I’ve found a tutorial where you show how to filter by a referenced element but this doesn’t seem to work once i enabled “multiple” on that categories field.
The code i have to filter it is the following:
function filter(text, category) {
if (lastFilterText !== text || lastFilterCategory !== category) {
let questionsFilter = wixData.filter();
if (text) {
questionsFilter = questionsFilter.contains(‘title’, text);
}
if (category) {
questionsFilter = questionsFilter.eq(‘categories’, category)
console.log(category);
}
$w(‘#questionsDataset’).setFilter(questionsFilter);
lastFilterText = text;
lastFilterCategory = category;
}
}
I’ve tried multiple things for the line questionsFilter = questionsFilter.eq('categories', category)
but nothing seems to work.
Any chance someone might now how that works?
Many thanks,
Kim