I am very new to coding so I would really need help to get a code for this topic.
In my database, I have an array field “multiCity” to put in all the cities that a provider operates in.
For example, provider A has [“New York”, “Boston”, “Las Vegas”]
provider B has [“New York”, “Boston”, “Dallas”]
provider C has [“New York”, “San Diego”, “Dallas”]
I would like to build a dropbox or checkbox that has unique option, and then I can set a filter button to filter out my repeater base on user selection.
I could only successfully get options for dropbox/checkbox if the database field is a string (like text) field. (codes showing bellow)
When i change the field back to array or tags, i will receive this error:
Wix code SDK error: The label parameter of item at index 0 that is passed to the options method cannot be set to the value New York,Boston,Las Vegas. It must be of type string
Please help me to understand how I can populate this dropbox/checkbox with array or tags field in database.
Thank you!
import wixData from ‘wix-data’ ;
$w.onReady( function () {
uniqueDropDown1();
});
function uniqueDropDown1 (){
wixData.query( “AllProviders” )
.limit( 1000 )
.find()
.then(results => {
const uniqueTitles = getUniqueTitles(results.items);
$w( “#multicitydropdown” ).options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.multiCity);
return [… new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}