I am trying to populate a dropdown list with code that uses the result from a query of a collection. I constructed an array and pointed the info to the dropdown but I don’t really know if I got the syntax right. I am getting the following error.
Wix code SDK error: The selectOption parameter of item at index 0 that is passed to the options method cannot be set to the value Test Option 1. It must be of type object.
And here’s my code:
export async function work_loader () {
wixData . query ( “Work” )
. lt ( “wTier” , pTier + 1 )
. find ()
. then ( w_result => {
console . log ( "Jobs Available: " , w_result . length ); var myArray = []; for ( let i = 0 ; i < w_result . length ; i ++) {
myArray [ i ] = w_result . items [ i ]. title ;
console . log ( "Job " , i , " is " , myArray [ i ])
}
$w ( “#dropdown1” ). options = myArray ;
})
. catch (( err )=>{ console . log ( err );});
}
Hi there I do something similar on my site. You’re thinking correctly in making an array, but within the array needs to be a Javascript object with a label and value to fill the dropdown.
Below is the code I use, update it to suit your query needs. You can check out this post where I got the idea from.
I have a collection, one column (height) should form the drop down and the other column should be output in a text box next to the drop down based on what the user selects in the drop down.
I’m only just beginning to explore Velo and have no coding background and so I am very new to this. Any pointers?
I am currently struggling to even populate the drop down without manually typing the array into the code.
Anyway I have managed to get it to work now with the below code. Like I say, I am new to this and so have probably broken multiple best practices and coding rules but hey it works .