I’m just getting started with Corvid and have a limited understanding of Javascript and programming in general.
I followed the video along relatively well ( https://www.youtube.com/watch?v=mTRSPNosLRw&t=256s ) and was able to get the search functionality working fine.
However, no matter how hard I try, I cannot get the dropdown filter to load the values from my dataset.
I’ve gone as far as copy-pasting the code from the sample and simply changing the values, but cannot get it to work.
Any ideas on what else I could look at?
Here’s my code. The only difference is instead of “Continents” I have “Categories” and “Artists”. I’ve tried with each by itself as well, but that hasn’t helped.
import wixData from “wix-data”;
$w.onReady( ()=> {
loadCategories();
loadArtists()
});
let lastFilterTitle;
let lastFilterCategory;
let lastFilterArtist;
let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iTitle’).value, lastFilterCategory);
}, 500);
}
export function iCategory_change(event, $w) {
filter(lastFilterTitle, $w(‘#iCategory’).value);
}
export function iArtist_change(event, $w) {
filter(lastFilterTitle, $w(‘#iArtist’).value);
}
function filter(title, category, artist) {
if (lastFilterTitle !== title || lastFilterCategory !== category || lastFilterArtist !== artist) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘videoTitle’, title);
if (category)
newFilter = newFilter.contains(‘category’, category);
if (artist)
newFilter = newFilter.contains(‘artist’, artist);
$w(‘#dataset1’).setFilter(newFilter);
lastFilterTitle = title;
lastFilterCategory = category;
lastFilterArtist = artist;
}
}
function loadCategories() {
wixData.query(‘Category’)
.find()
.then(res => {
let options = [{“value”: ‘’, “label”: ‘All Categories’}];
options.push(…res.items.map(category => {
return {“value”: category.title, “label”: category.title};
}));
$w(‘#iCategory’).options = options;
});
}
function loadArtists() {
wixData.query(‘Artist’)
.find()
.then(res => {
let options = [{“value”: ‘’, “label”:‘All Artists’}];
options.push(…res.items.map(artist => {
return {“value”: artist.title, “label”: artist.title};
}));
$w(‘#iArtist’).options = options;
});
}