I am displaying some data from a collection in a repeater.
The collection has a tag field and I want to display an image, in each item of the repeater for each of the tags that ware present. The images $w ( ‘#XTile’) all start out collapsed…and this is my code to only show the images for the where there is a tag.
For each item in the repeater, quickly do a loop through the array that contains the tags, expanding the image element where a tag is present but leaving it collapsed if the tag is not present.
$w.onReady( () => {
$w("#products").onReady( () => {
$w("#productsRepeater").forEachItem( ($item, itemData, index ) => {
let tiles = itemData.tiles
let i = tiles.length
while (i>0) {
let tile = tiles[i-1]
//console.log(element)
if (tile === "A") {$w('#ATile').expand()}
if (tile === "B") {$w('#BTile').expand()}
if (tile === "C") {$w('#CTile').expand()}
if (tile === "D") {$w('#DTile').expand()}
if (tile === "E") {$w('#ETile').expand()}
if (tile === "F") {$w('#FTile').expand()}
i--
}
})
})
})
It couldn’t really be any simpler but, this code is actually expanding all the images so I can see them all in each item of the repeater.
The console log statement, that I’ve commented out here, was showing the elements as I’d expected but all the image elements are expanded…but I can’t see what I’m doing wrong.
If I comment out the whole code block, the images are all collapsed correctly, as expected.
Can anyone throw any light on what I am doing wrong here??
Simon.