For each.item on repeater returns NaN

Hi, I have the following function, It is returning NaN for the number values… any help??


export function repeater2_viewportEnter(event) {

    $w("#repeater2").forEachItem(($item, itemData, index) => {

 let subtotali = Number("total")
        console.log(subtotali)
 let descuentoi = Number("descuento")
        console.log(descuentoi)
 let totali = Number("total")
        console.log(totali)

 let subtotalii = "" + fmt(subtotali)
 let descuentoii = "" + fmt(descuentoi)
 let totalii = "" + fmt(totali)

        $item("#text83").text = subtotalii;
        $item("#text84").text = descuentoii;
        $item("#text85").text = totalii;

    });

}

Thanks

Hi Alex

How are you?

I don’t understand what you are trying to achieve because I cannot see where the calculation is being executed but you are missing

;

in your calculation codes and since its a .text element you need to convert the values to String like below

$item("#text83").text = String(subtotalii);

Maybe do not use viewPortEnter and use something like onReady for Dataset or onItemReady for Repeater and surely check the code where the actual calculation is happening.

-Shan

You are trying to convert strings to numbers. Since your strings aren’t numeric strings, the result is NaN .

For example, you have:

let subtotali = Number("total")

The string “total” cannot be converted to a number so the result is NaN.

Another example:

let subtotali = Number("10");

This time, I am converting the string “10” to a number and the result is 10.

And yet another example:

let ten = "10";
let subtotali = Number(ten);

This time, I am converting the variable ten, which is the string “10”, to a number, and the result is 10.

I hope this helps clear up any confusion.