Hello everyone,
I am running a store which has more than 9000 products.
I want to show some randomly selected items on the main page. I managed it by hard-coding:
![](https://static.wixstatic.com/media/a27d24_9103615037c54fbd8c2eed646e3400b5~mv2.png/v1/fill/w_49,h_23,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_9103615037c54fbd8c2eed646e3400b5~mv2.png)
There are 12 images and 12 texts in the code. And I am assigning them separately with a for loop.
Is there any way to do this using a repeater?
My code:
let storeItems; let images = ["#image2", "#image3", "#image4", "#image5", "#image6", "#image7", "#image8", "#image9", "#image10", "#image11", "#image12", "#image13"]; let texts = ["#text32", "#text33", "#text34", "#text35", "#text36", "#text37", "#text38", "#text39", "#text40", "#text41", "#text42", "#text43"]; $w.onReady(function () { $w("#dataset1").onReady(()=> { for(let i = 0; i<12; i++){ $w("#dataset1").getItems(getRandomIndex(0, $w("#dataset1").getTotalCount()-1),1) .then( (result) => { storeItems = result.items; $w(images[i]).src = storeItems[0].mainMedia; $w(images[i]).link = storeItems[0].productPageUrl; $w(texts[i]).text = storeItems[0].name; }) } }); }); //random array index function getRandomIndex(min, max) { return Math.round(Math.random() * (max - min) + min); }
Thank you.