// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixWindow from 'wix-window';
import wixData from 'wix-data';
$w.onReady(async function () {
// Check the render env so this is just done once.
// Otherwise, server-side will render, and then the image
// switches to the image that the client-side rendered.
if (wixWindow.rendering.env === 'browser' || wixWindow.viewMode === 'Preview') {
let res = await wixData.query("Art").find();
let items = res.items;
let count = items.length; // how many images do we have?
let rnd = Math.floor(Math.random() * count);
$w('#image1').src = items[rnd].image; // get a random image
$w('#image1').show(); // image on page is hidden, we we now show it
}
});
I copied and pasted your code into a page and connected it to a collection with images, and it displayed random images as designed.
You might check the field key of the image field in the content manager. Is it all lower case like you have it?
Thanks got it. It was a problem with field key