Setting aggregate values to repeater (_id issue)

Hi,

Objective: I’m trying to aggregate the average prices of items in the content manager and display those unique results in a repeater

State of Play: In the console.log I can see the array is querying the database and pulling through the relevant average prices and the car’s make and model details in. The repeater only displays the last item in the array across every single container in the repeater, rather than each item in the array in each of the respective containers. I assume this is an “_id” issue as I can see that the _id for every item is “”.

Question: What do I need to do to get the repeater to display each individual item in the array rather than just the final item over and over again?

Code:

$w("#forSaleRepeater").forEachItem(($item, itemData, index) => {
        var decadeFilter = $w("#selectDecade").value
        var makeFilter = $w("#selectMake").value
        var minFilter = parseInt($w("#minPrice").value)
        var maxFilter = parseInt($w("#maxPrice").value)

        let theFilter = wixData.filter()
            .hasSome("decade", decadeFilter)
            .hasSome("make", makeFilter)
            .between("priceGbpNumber", minFilter, maxFilter)
            .ge("auction_date_short", "2019")
            .ne("priceGbpNumber", 0)
            .ne("model", "Other")

        wixData.aggregate("ScraperFinal")
            .ascending("model")
            .filter(theFilter)
            .group("make", "model")
            .avg("priceGbpNumber")
            .limit(1000)
            .run()
            .then((results) => {

                let count = results.items.length;
                console.log(count)

                for (var i = 0; i < results.items.length; i++) {
                    let make = results.items[i]["make"]
                    let model = results.items[i]["model"]
                    let value = results.items[i]["priceGbpNumberAvg"]
                    let id = results.items[i]["_id"]
                    let image = results.items[i]["image"]
                    $item("#text336").text = "£" + Math.round(value).toLocaleString('en-GB')
                    $item("#text337").text = model
                    $item("#text338").text = make
                    $item("#image93").src = image

                }

                let items = results.items;
                console.log(items)
            });
    })

Thank yous!

@yisrael-wix :slight_smile: any ideas please sir?

You’re using $w instead of $item (in the lines before the query). I’m not sure you want that. If you want that (in case all these inputs are not part of the repeater for all the items), you should only run the query once (outside the forEachItem).