SOLVED - Adding values in repeater without Dataset

Hi Wix team,

Hopefully someone can help me tweak this code. I’m trying to add values in a repeater with the code below:

let items = results.items;
            items.forEach((result) => {
 let   outstandingTotal = result.outstandingBalance;
                $w("#outstandingInvoiceTotal").text = String(outstandingTotal); //total should be displayed here
                console.log (outstandingTotal)
                });

I get a result in the text field but it’s only the last entry. Console log shows all of the values but it doesn’t add them together. I have done some research and looked at the API forEachItem and a working code for the use of a dataset here :
https://www.wix.com/corvid/forum/community-discussion/trying-to-sum-db-values-with-a-loop

But wondered if someone could help me with my code for no Dataset if this is possible?

Here the screen shot of the console log:


Thank you!

You can use onItemReady and set the data in that callback.
Make sure to use the $item(“#outstandingInvoiceTotal”) selector in order to populate the text element on the relevant item.

Thanks @ohad-laufer this is a little new to my coding toolbox, does this look like liek it’s in the right direction?

function fillRepeaterOutstandingBalance() {
    wixData.query('CourseAvailability')
        .gt("outstandingBalance", 0)
        .ascending("date")
        .find()
        .then((results) => {
 if (results.totalCount > 0) {
                $w('#outstandingPaymentsRepeater').data = results.items;
                $w('#outstandingPaymentsRepeater').onItemReady(($w, itemData, index, $item) => {
 //let items = results.items;
 let   outstandingTotal = itemData.outstandingBalance;
                $item("#outstandingInvoiceTotal").text = String(outstandingTotal); //total should be displayed here
                console.log (outstandingTotal)

//more repeater data here

Thanks ever so much for your help :slight_smile:

Working code:

 function fillRepeaterOutstandingBalance() { 	wixData.query('CourseAvailability') 		
 .gt("outstandingBalance", 0) 		
 .ascending("date") 		
 .find() 		
 .then((results) => { 			
 if (results.totalCount > 0) { 				$w('#outstandingPaymentsRepeater').data = results.items;                  
 // calculating total                  
 let items = results.items;                 
 let outstandingTotal = 0                 
 items.forEach((result) => {                     
 outstandingTotal += result.outstandingBalance;                 
 });                 
 $w("#outstandingInvoiceTotal").text = String(outstandingTotal); 
 //total should be displayed here                 
 console.log (outstandingTotal)   				$w('#outstandingPaymentsRepeater').onItemReady(($w, itemData, index) => {  
 
 //extra repeater code here  	
 			
       }) 			
 }}) }