I want to get my expenses sum, but filtered by the current month.
expenses: computed('transactions.length', 'transactions.@each.amount', function() {
return this.get('transactions').filterBy('typeOfT','expense').sortBy('date')
}),
filteredExpenses: computed('expenses.length', 'expenses.@each.amount', function() {
let thisMonth = new Date().getFullYear()+'-'+(new Date().getMonth()+1)
return this.get('expenses').filterBy('date', 'thisMonth').mapBy('amount').reduce((a, b) => a + b, 0)
}),
So trying the filterBy('date', 'thisMonth')
function didn't work. I thought this would be way easier, but it isn't. Using mapBy('amount')
and reduce((a, b) => a + b, 0)
I can get the array of all expenses and by using the function I calculate the sum.
Aucun commentaire:
Enregistrer un commentaire