Hi Guys,
Is there a more efficient way for me to write this code? basically i have multiple unique drop downs all reading the same column in a collection so i created this code but seems a bit long winded ! it works but was looking at it thinking there must be a more efficient option?
Cheers
Dan
import wixData from 'wix-data';
$w.onReady(function () {
foodDropdown();
});
function foodDropdown (){
wixData.query("FoodData")
.ascending("food")
.limit(1000)
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w("#foodDropdown11").options = buildOptions(uniqueTitles);
$w("#foodDropdown12").options = buildOptions(uniqueTitles);
$w("#foodDropdown13").options = buildOptions(uniqueTitles);
$w("#foodDropdown14").options = buildOptions(uniqueTitles);
$w("#foodDropdown15").options = buildOptions(uniqueTitles);
$w("#foodDropdown16").options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.food);
return [...new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}