@givemeawhisky Thanks again. Appreciate your desire to help.
I tried the following. But it doesn’t like the numberRecipes bit. I assumed that was for something else but whatever I change this too it doesn’t work.
I’ve amended the names of the repeater and data collection to my ones. Still doesn’t pull anything in.
import wixData from 'wix-data';
$w.onReady(function () {
// 1) get a random skip number
let max = numberRecipes - 3;
let skip = Math.floor(Math.random() * max) + 1;
// 2) query the database and get 3 random itmes
wixData.query("collection")
.ascending("title")
.skip(skip)
.limit(3)
.find()
.then( (results) => {
let items = results.items;
// 3) create a repeater data object from our retrieved data
let itemData = [
{
"_id":items[0]._id,
"text1":items[0].text
},
{
"_id":items[1]._id,
"text1":items[1].text
},
{
"_id":items[2]._id,
"text1":items[2].text
}
];
// 4) set the repeater data property with our data object
$w("#repeater1").data = itemData; // add data to our repeater
} )
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
// 5) method to handle each repeated item
$w("#repeater1").onItemReady( ($w, itemData, index) => {
// all we do here is set the repeated image from our data
const repeatedText = $w("#text1");
repeatedText.text = itemData.text1;
// you can do a whole lot more in this routine:
// - handle other fields or elements
// - add an onClick() handler
// - handle selected repeat items
});
});