what i'm doing wrong?

my code is broken when reloading the repeater
its work before…

how can i improve it to work?

import wixData from 'wix-data';

$w.onReady(function () {
    loadReapeter()
});

async function loadReapeter() {
    await wixData.query("testCollection")
        .find()
        .then((result) => {
            console.log("result: ", result)
            $w('#repeater').data = []
            $w('#repeater').data = result.items
            updateRepeater()
        })
}

function updateRepeater() {
    $w('#repeater').onItemReady(($item, itemData, index) => {
        $item('#repeaterTxt').text = itemData.title

        $item("#repeaterBox").onMouseIn((event) => {
            if (event.context.itemId === itemData._id) { $item("#repeaterBox").style.backgroundColor = "lightblue" }
        })
        
        $item("#repeaterBox").onMouseOut((event) => {
            if (event.context.itemId === itemData._id) { $item("#repeaterBox").style.backgroundColor = "white" }
        })

    })

}

export function reloadRepeater_click(event) {
    loadReapeter()
}

So what is the expected behaviour?

i’m expecting that repeater box will change color when mouseIn and back to white when mouseOut

this code working only until i’m reloading the data loadReapeter ()

example page

https://naimibaby.wixsite.com/my-site-1/

Hi @naimibaby ,

I think because you already have an onitemReady running it is not working correct when reloading the data.

Add the updateRepeater code inside the onReady code.
And remove the updateRepeater function from the loadRepeater.

Hope it works
Kind regards,
Kristof

@volkaertskristof Thanks
i have found the issue

i removed that - $w ( ‘#repeater’ ). data = []
and its working again

i dont now what was changed
this code was working fine for 2 years

@naimibaby your code could get shorter using it like this:

import wixData from "wix-data"

$w.onReady(async () => {
    loadReapeter()
    $w("#repeater").data = await getData()
})

async function getData() {
    const result = await wixData.query("testCollection").find()
    return result.items
}

function loadReapeter() {
    $w("#repeater").onItemReady(($item, itemData, index) => {
        $item("#repeaterTxt").text = itemData.title

        $item("#repeaterBox").onMouseIn(() => {
            $item("#repeaterBox").style.backgroundColor = "lightblue"
        })

        $item("#repeaterBox").onMouseOut(() => {
            $item("#repeaterBox").style.backgroundColor = "white"
        })
    })
}

@volkaertskristof after building my pages from 0
i have understood that $w ( ‘#repeater’ ). data =
was not the issue, it just start the issue faster

the real issue is when the $w ( ‘#repeater’ ). data data changes
like when you making a search for specific item so you loading the repeater data with less items,
and its work
but when you changing it back or search for other item it doesn’t work anymore

you can test it here:

https://naimibaby.wixsite.com/my-site-1/test2