I need a code to randomize items from a repeater.
I tried some codes with random.math, but none of them worked.
researched and found nothing about.
I need a code for the repeater to select exactly 5 items from all 50 items in a database.
I need a code to randomize items from a repeater.
I tried some codes with random.math, but none of them worked.
researched and found nothing about.
I need a code for the repeater to select exactly 5 items from all 50 items in a database.
See the Random Gallery example. Just use the random results of the query for a Repeater instead of a Gallery,
Use the .data property. Make sure all of the items have an _id field as described in the API.
@yisrael-wix the items are not being chosen dynamically, I do not understand much of the codes.
$w.onReady(async function () {
// Check the render env so this is just done once.
// Otherwise, server-side will render, and then the gallery images
// switch to the gallery images that the client-side rendered.
if (wixWindow.rendering.env === 'browser' || wixWindow.viewMode === 'Preview') {
let res = await wixdata.query("filtroscomission").find();
let items = res.items;
let count = items.length; // how many images do we have?
const size = 3; // # of images to display in the gallery
var rnd = [];
while (rnd.length < size) {
var r = Math.floor(Math.random() * count);
if (rnd.indexOf(r) === -1) rnd.push(r);
}
$w("#repeater1").data = [{
"_id": items[rnd[1]]._id,
"title": items[rnd[1]].title,
"image": items[rnd[1]].image
},
{
"_id": items[rnd[2]]._id,
"title": items[rnd[2]].title,
"image": items[rnd[2]].image
}
]
}
});