Change item element from listRepeater according to one of the database variables

Hi!

I want to change the colour of an element inside an item from a listRepeater according to the value of one of the fields. I tried with this code:
$w . onReady ( function () {
$w ( “#listRepeater” ). onItemReady ( ( $item , itemData , index ) => {
let state = $item ( “#text17” ); → This is a text containing the value of a variable in the database.

    **if**  ( state . text  ==  "fine" ){ 
        $w ( "#box1" ). style . backgroundColor = "#333333" 
    } 
    **else if**  ( state . text  ==  "bad" ){ 
        $w ( "#box1" ). style . backgroundColor = "#222222" 
    }       
}); 

The problem I saw is this onItemReady() can not be used as a regular “for” loop. Each “backgroundColor” execution will change all instances of #box1. So, the final result will be that all boxes of the list painted with the color of the last item of the list.

How can I achieve the result I want? Maybe not using onItemReady() funciton and use a regular “for” loop to print all elements in database?

Thanks!

If you would use the —> onItemReady()-method the right way → everything would work like expected!

WRONG!

$w("#box1").style.backgroundColor="#333333"

RIGHT!

$item("#box1").style.backgroundColor="#333333"

:sweat_smile: thanks so much to point out this “mistake”. Now, obviously, it works.

thanks! :slight_smile: