Populating Selection-Tags is nothing else as populating - → DropDowns.
If you can populate DropDowns - → you also should be able to populate → S-Tags.
There are just some differences in which FIELD-TYPE is used…
- FIELD-TYPE —> ARRAY
- FIELD-TYPE ----> TAGS
But at all both works like arrays.
Let’s say this is your S-Tag-Array: including two OBJECTS → Onion & Carrot
[ { "label": "Onion", "value": "Onion"}, { "label": "Carrot", "value": "Carrot"} ];
Let’s say your DB-FIELD-ID of TYPE ARRAY is → myArray.
And let’s say you have found exactly the data-row, you were looking for in your DB.
let myArray = results.items.myArray; console.log(myArray);
Now you can get every single item of the ARRAY-FIELD like…
let arrayResult1 = results.items.myArray[0]; console.log(arrayResult1);
let arrayResult2 = results.items.myArray[1]; console.log(arrayResult2);
As Result you will get each object which is inside your DB-Array…
{ "label": "Onion", "value": "Onion"}
…&…
{ "label": "Carrot", "value": "Carrot"}
If you want to get the label —> Onion
let arrayResult = results.items.myArray[0].label; console.log(arrayResult);
If you want to get the value —> Onion
let arrayResult = results.items.myArray[0].value; console.log(arrayResult);
This is how we populate our S-Tag-Element…
let options = $w("#myStagElementIDhere").options;
options.push({"label": "Olives", "value": "olives"});
$w("#myStagElementIDhere").options = options;
First —> getting the current options out of our S-Tag-Element…
let options = $w("#myStagElementIDhere").options;
Second —> we push new values into the new generated ARRAY, called → options
options.push({"label": "Olives", "value": "olives"});
Third —> we put/push back the new generated ARRAY with the new generated DATA…
$w("#myStagElementIDhere").options = options;
…to our S-Tag-Element.
It’s the same process, like on dropdowns.
To populate multiple items/values into a DropDown or S-Tag-Element, you will need to use a → LOOP (either a for-loop, or an each-loop).
Good luck!