Setting repeater data not working

I’ve been using velo code on my site for a few years now, and usually everything seems to work just fine.
However, after recently adding a new repeater to my page, with a query and some code for defining the object-array to be used in the onReady function, I’ve run into a the following problem: setting the data field of the repeater object isn’t doing anything! I added some console-logs to debug the issue, and I get the following results:

console.log('About to set repeater data...'); 
console.log(results.items); // shows a non-empty array as intended
$w('#recentChatRepeater').data = results.items; // theoretically sets the data field and triggers the onReady function
console.log($w('#recentChatRepeater').data) // shows that the data field has not been set, is still empty, and as a consequence the repeater's onReady isn't triggered either...

I’m not trained or experienced in javascript, and I’m assuming I’m missing something simple, but the same kind of code has worked for other repeaters on my site, and the situation looks pretty straightforward to me…

What am I doing wrong? :frowning:

Anyone? Is there maybe a programers-oriented Velo-focused forum I can post on?
Thanks…

without seeing all the code it is hard to see exactly, but from what you have posted it the issue might be due to the structure of the results.items array. The data property of a repeater expects an array of objects, where each object represents a row of data in the repeater. Each object should contain properties that correspond to the IDs of the elements in the repeater’s item.

1 Like

I actually encounter this problem as well. which i am not sure why. I am trying to set a wixData.aggregate result to the repeater. the repeater is showing the ranking of salesman based on sales volume. I am doing this for 2 repeaters, where 1 is for this month’s top salesman and last month’s top salesman.

it works fine when i set the data for the first repeater but it is unable to set the data for the second repeater.

i was thinking maybe it was an issue with my code structure. (maybe code is placed at the wrong place).

Blockquote

async function populatetopsales() {
let todayyear = new Date().getFullYear();
let todaymonth = new Date().getMonth();

//edit month and year to correct month and year
if (todaymonth == 12) {
    todaymonth = 1;
} else {
    todaymonth = todaymonth + 1;
}

let lastmonthmonth = todaymonth - 1;
let lastmonthyear = todayyear;

// do correction if in case got through a new year
if (lastmonthmonth == 0) {
    lastmonthmonth = 12;
    lastmonthyear = lastmonthyear - 1;
}

//change the year and month to fy format for this month
if (todaymonth == 10 || todaymonth == 11 || todaymonth == 12) {
    todayyear = todayyear + 1;
}

if (todaymonth == 10 || todaymonth == 11 || todaymonth == 12) {
    todaymonth = todaymonth - 9;
} else {
    todaymonth = todaymonth + 3;
}

//change the year and month to fy format for last month
if (lastmonthmonth == 10 || lastmonthmonth == 11 || lastmonthmonth == 12) {
    lastmonthyear = lastmonthyear + 1;
}

if (lastmonthmonth == 10 || lastmonthmonth == 11 || lastmonthmonth == 12) {
    lastmonthmonth = lastmonthmonth - 9;
} else {
    lastmonthmonth = lastmonthmonth + 3;
}


//this month
let filter = wixData.filter().eq("fyYear", todayyear).eq("fyMonth", todaymonth);
let topsales = await wixData.aggregate("Sales-Listing").filter(filter).sum("sellingPrice", "sellingPriceSum").group("salesman2").limit(3).descending("sellingPriceSum").count().run();

if (topsales.items.length > 0) {
    console.log("topsales list " + String(todayyear) + " " + String(todaymonth))
    $w("#repeater5").data = topsales.items;
    console.log("successfully input top sales data")
    console.log($w("#repeater5").data)
} else {
    $w("#repeater5").data = topsales.items;
    console.log("unsuccessfully input top sales data")
}

$w("#repeater5").onItemReady(async ($item, itemData, index) => {
    $item("#button3").label = String(index + 1);
    $item("#text933").text = itemData.salesman2;
    $item("#text934").text = "RM " + formatNumber(itemData.sellingPriceSum);
    $item("#text935").text = String(itemData.count) + " unit";

    let salesmanData = await wixData.query("Employee-Listing").hasSome("name", itemData.salesman2).find()

    if (salesmanData.items.length > 0) {
        // console.log(salesmanData.items[0])

        $item('#imageX9').src = salesmanData.items[0].employeeImage;
    }
});

//last month
let filter2 = wixData.filter().eq("fyYear", lastmonthyear).eq("fyMonth", lastmonthmonth);
let topsales2 = await wixData.aggregate("Sales-Listing").filter(filter2).sum("sellingPrice", "sellingPriceSum").group("salesman2").limit(3).descending("sellingPriceSum").count().run();

if (topsales2.items.length > 0) {
    console.log("topsales list " + String(lastmonthyear) + " " + String(lastmonthmonth))
    $w("#repeater6").data[0] = topsales2.items[0];
    console.log("successfully input top sales data")
    console.log($w("#repeater6").data)
} else {
    $w("#repeater6").data = topsales2.items;
    console.log("unsuccessfully input top sales data")
}

$w(“#repeater6”).onItemReady(async ($item, itemData, index) => {
$item(“#button4”).label = String(index + 1);
$item(“#text938”).text = itemData.salesman2;
$item(“#text937”).text = “RM " + formatNumber(itemData.sellingPriceSum);
$item(”#text936").text = String(itemData.count) + " unit";

    // let salesmanData = await wixData.query("Employee-Listing").hasSome("name", itemData.salesman2).find()

    // if (salesmanData.items.length > 0) {
    //     console.log(salesmanData.items[0])

    //     $item('#imageX10').src = salesmanData.items[0].employeeImage;
    // }
});

}