Text box displaying Age from a DOB field not showing on repeaters

Here is my problem, I am trying to develop a Members page that display a little overview of each member of the website, showing the picture, first name, city and age.
I was able to link all fields by simply using the Connect Repeater button.

But the age that is causing the issue.

I was able to get the total age by applying a code to transform the data input by the user to yyyymmdd and then transforming this date to the total age.

But when trying to link this text box that is inside of a repeater, to the code, when previewing, my code works, but it displays the first entry in my dataset, as if everyone has the same age, so it’s not calculating the others.

Anyone had the same issue?


$w.onReady( function () {
// Get the date from the date field of the current item
const date = $w( “#MembrosDataset” ).getCurrentItem().aniversario;
var nowms = Date.now();
var age = Math.floor((nowms - date) / ( 365.25 * 24 * 60 * 60 * 1000 ));
// Set the text element to display the date using the user’s settings
$w( “#AgeField” ).text = age.toString();
});

@vanny Putting your code in an onItemReady function for the repeater will allow you to apply the age calculation to each item. Rather than using getCurrentItem(), the itemData object parameter has the data for the repeated item. Instead of using $w to refer to the #AgeField element, you use $item for the repeated item.

$w.onReady(function () {
    $w("#MembrosDataset").onReady(() => {
       $w("#repeater1").onItemReady( ($item, itemData, index) => {
         // Get the date from the date field of the current item
         const date = itemData.aniversario;
         var nowms = Date.now();
         var age = Math.floor((nowms - date) / (365.25 * 24 * 60 * 60 * 1000));
         // Set the text element to display the date using the user's settings
         $item("#AgeField").text = age.toString();
       });     
    })
});

Thank you so much for educating me Anthony, it worked perfectly!!!