HI
I have this code that i use to create a unique list for the drop down muscleGroupdropdown. which is working fine for one.
How do i add another unique list drop down "exerciseTypedropdown" to this code? where do i place it ? its coming from same data set "Training"
i also want to have those 2 drop downs sorted A to Z and cant figure out where i place the .Ascending sort function the code below.
Thanks
Dan
import wixData from "wix-data"; $w.onReady(function () { wixData.query("Training") .limit(1000) .find() .then(results => { const uniqueItems = getUniqueItems(results.items); $w('#muscleGroupdropdown').options = buildOptions(uniqueItems); }); function getUniqueItems(items) { const itemsOnly = items.map(item => item.muscleGroup); return [...new Set(itemsOnly)]; } function buildOptions(uniqueList) { return uniqueList.map(curr => { return { label: curr, value: curr }; }); } }); export function searchButton_click(event) { $w('#trainingDataset').setFilter(wixData.filter() .contains("muscleGroup", $w('#muscleGroupdropdown').value) .contains("exerciseType", $w('#exerciseTypedropdown').value)) .then((reslts) => { console.log("Data is now filtered!"); $w('#listRepeater').data = reslts.items; }).catch((err) => { console.log(err); }); $w('#listRepeater').expand(); }
OK thanks
Perhaps you can/will find your answer here....
https://www.media-junkie.com/pflegeservice
Take a look onto the ORIGINAL-POST.
And here is an upgraded function....(to be found in action in the given example).
var DropDowns = [] var DATABASE = "yourDatabaseHere" DropDowns[0] = "xxx" DropDowns[1] = "yyy" DropDowns[2] = "zzz" async function uniqueTitles_DropDowns() {console.log("load_UniqueTitles for DropDowns") let dbDATA = await wixData.query(DATABASE) let Options = [] for (var a = 0; a < DropDowns.length; a++) { if(DropDowns[a]!==undefined && DropDowns[a]!=="undefined" && DropDowns[a]!==null) { await dbDATA.distinct(DropDowns[a]) .then((results) => { let items = results.items for (var b = 0; b <items.length; b++) { Options.push([]) Options[a].push({"label": items[b], "value": items[b]}) } $w('#myDropdown'+(a+1)).options = Options[a] $w('#myDropdown'+(a+1)).placeholder = DropDowns[a] }) } } }
Good luck & happy coding! 😉