hi
I have images in my dataset but not for all the rows.
i want to hide the image element if there is no image in the row but can’t figure it out.
This is the code that i have but it didn’t work.
$w(“#dbSystem”).onReady(() => {
let itemIndex = $w(“#dbSystem”).getCurrentItemIndex(); let location = $w(“#dbSystem”).getCurrentItem(); let count = $w(“#dbSystem”).getTotalCount();
console.log("Size of the Dataset: ", count);
let items = result.items; let image = items[0].image; let totalCount = result.totalCount; let hasimage = items[0].hasimage2; let index = result.offset; let postImage = $w(“#postImage”);
console.log("Item Index: ", index);
console.log("Items here: ", image);
console.log("Items location: ", location);
if (hasimage) {
postImage.show();
} else
postImage.hide();
The line items[2].postImage.show(); isn’t correct because: 1 . items[2] represent result.items[2]- this item is undefined, because each iteration at the loop, you only get one item from the collection. 2. You wish to hide only the image element, as a result your condition should be:
if (hasimage) {
postImage.show();
} else
postImage.hide();
Note that there’s an unnecessary forward -slash near the end of your code. .
This is still doesn’t work.
the " items[2].postImage.show() " was just for trying somthing and I forgat to change it before I posted here.
this is how my code look if (hasimage)
{ postImage.show (); } else
postImage.hide();
but its just show all the items even if there isn’t image in it (from the dataset)
First, I suggest to disconnect the repeater’s elements from the dataset, because if you wish to set the image element by using code, its more correctly to also set by code the other elements.
At the follow code I used an event handler that run when the dataset’s ready, and at the handler I summoned the function imageMngr() that you wrote.
At the function imageMngr(), I used the onItemReady() event handler in order to set the repeater’s data. This function runs when a new repeated item is created, and as a result, I can set the image element before the item is presented in the repeater. Here you can read more about that.
*At the onItemReady() function, the ItemData is the object from the repeater’s data array that corresponds to the repeated item being created.
this solution worked for me iam able to collapse imagebox which are empty. thank you.
you can have a look atmy code and the result on my webpage ,one item contains image andon the other it has collapsed as it is empty