Hi there,
Can someone tell me where I went wrong? I added a search button and a dropdown menu(Location) but the dropdown menu does not function for some reason..
import wixData from 'wix-data'; $w.onReady(() => { loadlocation(); }); let lastFilterjobTitle; let lastFilterlocation let debounceTimer; export function iTitle_keyPress(event, $w) { if (debounceTimer) { clearTimeout(debounceTimer); debounceTimer = undefined; } debounceTimer = setTimeout(() => { filter($w('#iTitle').value, lastFilterlocation); }, 500); } export function iLocation_change(event, $w) { filter(lastFilterjobTitle, $w('#iLocation').value); } function filter(jobTitle, location) { if (lastFilterjobTitle !== jobTitle || lastFilterlocation !== location) { let newFilter = wixData.filter(); if (jobTitle) newFilter = newFilter.contains('jobTitle', jobTitle); if (location) newFilter = newFilter.contains('location', location); $w('#dataset13').setFilter(newFilter); lastFilterjobTitle = jobTitle; lastFilterlocation = location; } } function loadlocation() { wixData.query('location') .find() .then(res => { let options = [{"value": '', "label": 'All Location'}]; options.push(...res.items.map(location => { return {"value": location.jobTitle, "label": location.jobTitle}; })); $w('#iLocation').options = options; }); }
Any help will be highly appreciated
import wixData from 'wix-data'; let lastFilterjobTitle; let lastFilterlocation let debounceTimer; $w.onReady(() => { //STEP-1: Loading DropDown --> (LOCATIONS) loadLocations(); //DropdDown-Change (LOCATIONS) $w('#iLocation').onChange(()=>{ //selected VALUE... let myValue = $w('#iLocation').value; //Last filtered job-title??????? //Where is it? //Ok, starting filtering function.... filter(lastFilterjobTitle, myValue); }); $w('#iTitle').onKeyPress((event)=>{ if (debounceTimer) { clearTimeout(debounceTimer); debounceTimer = undefined; } debounceTimer = setTimeout(() => { filter($w('#iTitle').value, lastFilterlocation); }, 500); }); }); function filter(jobTitle, location) { // jobTitle = undefined!!! // and again cheking lasterFilteredJobTitle against current jobTitle? // Whats going on here? // Till here you never selected lastFilteredJobTitle !!!! // lastFilterjobTitle = undefined !!!! // jobTitle = undefined !!!!! if (lastFilterjobTitle !== jobTitle || lastFilterlocation !== location) { let newFilter = wixData.filter(); if (jobTitle) { newFilter = newFilter.contains('jobTitle', jobTitle); } if (location) { newFilter = newFilter.contains('location', location); $w('#dataset13').setFilter(newFilter); lastFilterjobTitle = jobTitle; lastFilterlocation = location; } } } function loadLocations() { wixData.query('location') .find() .then(res => { let options = [{"value": '', "label": 'All Location'}]; options.push(...res.items.map(location => { return {"value": location.jobTitle, "label": location.jobTitle}; })); $w('#iLocation').options = options; }); }