[Vuejs]-How to get total running balance with Vue js (Nested Array)

0👍

Since may nested array index is using ID as index so I make it like this v-for="(subFetch,key,count) in fetch.subPayments" to get the index starting with 0

<table>
//...
<tbody v-for="(fetch,count,idx) in soaData">
<tr>
 // code
</tr>
<template v-for="(subFetch,key,count) in fetch.subPayments" >
<tr>
    <td class="text-right">{{subFetch.AmountApplied | formatNum}}</td>
    <td class="text-right">{{getRunningBal(fetch.subPayments,fetch.amortId)}}</td>
</tr>
</template>
</tbody>
</table>

I get the index of subPayments to get the sum of each line and it works

    getRunningBal(subPayments,amortId, count){    
    let subpayCount = Object.values(this.soaData[amortId].subPayments).length
    let data = Object.values(this.soaData[amortId].subPayments)

    var total = 0;
    for(let i=0; i <= count; i++){              
     total += data[i].AmountApplied
    }
        return total       
    },

Leave a comment