As I work on developing a mobile application using Ionic 2, my current task involves calculating the total allocation sum (Course.allocation) for each year per horse in the database.
For instance: Table: Course (Race):
[Id_course: 1, allocation: 200, date: 10/03/2012, idcheval: 1]
...[Id_course: 4, allocation: 600, date: 10/03/2013, idcheval: 1]
Engagement table:
[2012, 2013]
The desired display format should be:
2012 ====> 500
2013 ====> 1300
I could really use some assistance with this. Can anyone help?
JSON
{
// JSON data here
}
Template
<ion-row *ngFor="let ch of cheval1 ">
{{ch[0].annee }}
<div *ngFor="let m of members ; let rowIndex = index">
<ion-col *ngIf="ch[0].annee == (m.Course.date |date : 'yyyy' )">
{{ m.Course.allocation}}
</ion-col>
</div>
Component
allocationSum: number;
// other variables
getIdCheval() {
this.allocationSum = this.members.reduce((previous, current) => {
return previous + parseInt(current.Course.allocation);
}, 0);
}