Hi,
When my pages opens up, I have 6 different dropdowns which are populated based on the unique elements in a collection for the respective filter. I would like to save that full list of values, however I am somehow not able to do.
Here is the code:
$w.onReady(() => {
createDropdown("category", "#categoryLocation");
createDropdown("typeOfLocation", "#typeOfService");
createDropdown("price", "#priceRangeDropdown");
createDropdown("capacity", "#capacityDropdown");
createDropdown("rating", "#ratingSelection");
createDropdown("region", "#allRegions");
createDropdown("place", "#allPlaces");
});
unction createDropdown(category, dropDownName) {
wixData.query("Wedding_Database")
.limit(10)
.ascending(category)
.distinct(category)
.then(results => {
let distinctList = buildOptions(results.items);
// Add "Alle" to the existing list
distinctList.unshift({ "value": '', "label": 'Alle' });
// build the unique elemnt list
$w(dropDownName).options = distinctList;
});
}
function buildOptions(items) {
return items.map(curr => {
// Use the map method to build the options list in the format {label:uniqueTitle, value:uniqueTitle}
return { label: curr.toString(), value: curr.toString() };
});
}
I tried a number of different things, among others, but nothing gives me the results I am looking for.
//let myFullListCategories = dropdownOptions[0].value;
//let myFullListCategories = $w("#categoryLocation").options.value;
Thanks a lot for your help!
Firstly, you are missing the f from function.
As mentioned in your previous post...
I have a number of filters that get all populated using unique values from a collection....
https://www.wix.com/corvid/forum/community-discussion/create-a-function-that-populates-a-dropdown-with-unique-values-from-a-collection-with-both-numbers-of-strings
You should have a look at using a onAfterQuery hook and combining all the values into one.
https://www.wix.com/corvid/reference/wix-data.Hooks.html#afterQuery
https://support.wix.com/en/article/corvid-about-data-hooks
There are previous forum posts that can help with this too.
https://www.wix.com/corvid/forum/community-discussion/afterquery-data-hook-not-firing
https://www.wix.com/corvid/forum/community-discussion/combining-data-of-several-fields-into-one-for-multiple-search-boxes