reviews repeater using .foreachitem and .loadmore

hi everyone
i have almost got the reviews working,
i have a boolean on the review for, recommend, yes or no.
i am displaying this on my reviews, it works but then when i press my load more button it doesn’t repeat this onready function.
i dont really know what im doing, im new to this.
any help appreictaed.
cheers

//-------------Data Setup -------------//

// Perform some setup when the dataset filter was completed.
export function showReviews() {
// If at least one review has been submitted:
if ($w( ‘#Reviews’ ).getTotalCount() > 0 ) {
// Expand the strip that displays the reviews.
$w( ‘#reviewsStrip’ ).expand();
// If there are no reviews:
} else {
// Collapse the strip that displays the reviews.
$w( ‘#reviewsStrip’ ).collapse(); //otherwise, hide it
}
}

// Set the action that occurs when a user clicks the “Load More” text.
export function resultsPages_click(event, $w) {
// Load additional reviews into the reviews repeater.
$w( ‘#Reviews’ ).loadMore();
}

$w.onReady( function () {
$w( ‘#Reviews’ ).onReady( () => {
$w( ‘#reviewsRepeater’ ).forEachItem(($w, itemData, index) => {
if (itemData.recommends){
$w( ‘#recommendation’ ).text = “I Recommend This Product” ;
}
else {
$w( ‘#recommendation’ ).text = “I Dont’ Recommend This Product” ;
}
} );
} );
} );

Try using the $item scope

$w.onReady(function () {
    $w('#Reviews').onReady( () => {
           $w('#reviewsRepeater').forEachItem(($item, itemData, index) => {
           if(itemData.recommends === true){
                         $item('#recommendation').text = "I Recommend This Product";          
                         }else {
                                       $item('#recommendation').text = "I Dont' Recommend This Product";
                                                 }
                                                       } );
                                                         } );
                                                         } );

First, Ajit is correct and you need to use the the $item scope selector.

A dataset onReady() function does not “repeat”. It runs once - when the dataset is ready. Also, the forEachItem() function only runs when it’s called, it does not automatically run again when the Repeater data is changed. So, what happened was that when the dataset became ready, the forEachItem() function ran, but it won’t run again.

I would suggest using onItemReady() instead, and moving it out of the dataset onReady() event handler. Something like this:

$w.onReady(function () {
    $w('#reviewsRepeater').onItemReady(($item, itemData, index) => {
       if (itemData.recommends === true) {
          $item('#recommendation').text = "I Recommend This Product";
       } else {
          $item('#recommendation').text = "I Dont' Recommend This Product";
       }
    });
});

BTW - here’s a simple Ratings example that might prove useful.

thank you for your help :slight_smile:

thanks for your help.
i really need to find some time to research so i can fully understand how the code works 100% :slight_smile:
thanks again