How would I create a loop for this,
$w("#dropTier").options = [
{"label": "" + tierss[0].TierName, "value":"0"},
{"label": "" + tierss[1].TierName, "value":"1"},
{"label": "" + tierss[2].TierName, "value":"2"},
{"label": "" + tierss[3].TierName, "value":"3"},
{"label": "" + tierss[4].TierName, "value":"4"},
{"label": "" + tierss[5].TierName, "value":"5"},
];
Instead of writing it all out, I would need to do it many times on my page and I know there is an easier way. I have been trying to find a way to do it for a few hours and my brain hurts.
Thanks
You could add the options to a js file once and then call them whenever you need to populate a dropdown.
//filename.js file let tierss = [value1, value 2,...] export const name = [ {"label": "" + tierss[0], "value":"0"}, {"label": "" + tierss[1], "value":"1"}, {"label": "" + tierss[2], "value":"2"}, {"label": "" + tierss[3], "value":"3"}, {"label": "" + tierss[4], "value":"4"}, {"label": "" + tierss[5], "value":"5"}, ];
Then import it and call it for any dropdown that you need values for:
import {name} from 'public/filename.js'; $w("#dropTier").options = name;