I have a dataset called #dynamicDataset that is connected to a collection called Accounts. The Accounts collection has 2 fields ‘Amount’ and ‘Transaction Type’. I have a list repeater called #listrepeater that contains 3 fields. The first two fields are called #amount and #transactionType and are linked to #dynamicDataset. The 3rd field on #listrepeater is called #balance and is NOT connected to #dynamicDataset. The reason for this is that I want the #balance calculation to be calculated on the fly, every time the page loads.
Below is my code. The first 2 fields (Amount, Transaction Type) are populated correctly on screen, and the balance is worked out correctly (when I put in some logs). The problem is that the value of balance is not showing up on the list repeater. In the below snippet I marked where the code is not doing what I want it to do.
For clarity, if my collection contains 20 records, I need those 20 records to show up, and I need the balance to be calculated for each row, and the balance to show on screen for each record.
$w . onReady ( function () {
let previousBalance = 0 ;
$w ( ‘#listRepeater’ ). onItemReady (( $item , itemData , index ) => {
const amount = itemData . amount ;
const transactionType = itemData . transactionType ;
let calculatedBalance ;
**if** ( transactionType === 'Debit' ) {
calculatedBalance = amount - previousBalance ;
} **else if** ( transactionType === 'Credit' ) {
calculatedBalance = amount + previousBalance ;
}
$item ( '#balance' ). text = calculatedBalance ; <-- HELP!
previousBalance = calculatedBalance ;
});
});