Drop Down Elements

First post. I’m an old programmer but new to WIX.

I have a dropdown that I want to hide / show certain elements based on whether the user is logged on or not. The elements are static in the dropdown. I am able to determine if the user is logged on or not.

I guess I was expecting a way to iterate each of the elements in the dropdown…

function setDropdownOptions(){
wixUsers.currentUser.loggedIn ? $w('#dorpdown1').options = memberOptionArray : $w('#dorpdown1').options = visitorOptionArray;
}

and call it whenever you need.

Just to make it even shorter.

function setDropdwonOptions() {
    $w('#dropdown').options = wixUsers.currentUser.loggedIn ? memberOptionArray : visitorOptionArray
}

Something like this:

import wixUsers from 'wix-users'

$w.onReady(() => {
    const currentUser = wixUsers.currentUser
    const dropdownOptions = $w('#dropdown').options //Change this to your element
    const notAllowedOptions = ['cheese', 'yogurt', 'milk'] //This is an example

    //Create your own logic here, this is an example
    if (currentUser.loggedIn === true) {
        const newDropdownOptions = dropdownOptions.filter(
            item => !notAllowedOptions.includes(item.value)
        )
        $w('#dropdown').options = newDropdownOptions
    }

})

Perhaps you also should take a look onto this one…(here you will get some more informations about DROPDOWNS)…