I am seeking assistance in automatically calculating the sums of objects retrieved each time I click a button to fetch data. However, I am unsure about how to proceed with this task.
Below is the script responsible for fetching the data every time the button is clicked:
createTrade (zoneId, cycleId) {
this.getTrade().then(trade => {
let zone = this.zones.find(zone => zone.id === zoneId);
zone.cycles.map(cycle => {
if (cycle.id === cycleId) {
return {...cycle, ...cycle.trades.push(Object.assign(trade, {
account: this.accounts.find(acc => acc.id === this.form.accountId)
}))}
}
console.log(this.trade.realizedPL);
return cycle;
});
this.form = {
accountId: "",
tradeId: null
};
}).catch(() => {
alert('Trade does not exist');
});
},
Here are the objects that I am able to retrieve. I aim to add all the "realizedPL" values each time new data is fetched by clicking the button.
https://i.sstatic.net/Jodry.png
English is not my native language, so please forgive me if my explanation is confusing. I hope someone can provide assistance. Thank you!