Hello.
I created a tags collection and I want to populate my Selection Tag element using the tags stored on the database.
I've come as far as been able to query the tags from the collection:
wixData.query("myCollection") .find() .then( (results) => { console.log(results.items[0].myTags);
????????????? } );
I put all my 30 tags on a single cell of "myCollection". Thats why "results.items[0]"
I know that the code to populate the tags without querying it from a collection is:
$w('#selectionTags1').options = [ { "label": "Onion", "value": "Onion"}, { "label": "Carrot", "value": "Carrot"} ];
Thank you
This thread is old and will be closed, if you have any questions or concerns feel free to open up a new thread instead of bumping up old ones.
@joao dantas , @Chance Watkins this is the code I went with to get tag labels and values from the database collection. ~~~~~~~~~~~~~~~~~
import wixData from 'wix-data'; $w.onReady(function () { wixData.query("Courses") //this is my collection - make sure you use the collection ID, not the Collection name - check - it may have changed!! .find() .then((r) => { let tags = []; r.items.forEach((r) => { tags.push(r.tags) //'tags' is the field name within the collection }) const uniqueTags = [...new Set(tags.flat(1))] //we needed to get rid of the duplicate tags within each record of the field. const options = uniqueTags.map((r) => ({label: r, value: r})) $w("#typeTags").options = options; //typeTags is the name of my tag cloud element. }) }); export function typeTags_change(event) { let tagValue = $w("#typeTags").value; $w("#dynamicDataset").setFilter(wixData.filter().hasSome("tags", tagValue)) .then(() =>{ $w("#resetText").show(); }) }
//this next bit is to reset the filter. I also have a contracted strip that the filters are placed on. export function resetText_click(event) { $w("#dynamicDataset").setFilter(wixData.filter()) .then(() =>{ $w("#resetText").hide(); $w("#typeTags").value = []; }) } export function filter_click(event) { $w('#tagsStrip').expand() } Hope this helps! #createtagsfromdatabasecollection
poke. Just gonna leave this comment here to see if anyone wants to answer this.