Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 使用*ngfor计算角度2和离子2中阵列元素的和_Angular_Typescript_Ionic Framework - Fatal编程技术网

Angular 使用*ngfor计算角度2和离子2中阵列元素的和

Angular 使用*ngfor计算角度2和离子2中阵列元素的和,angular,typescript,ionic-framework,Angular,Typescript,Ionic Framework,我用ionic 2开发了一个移动应用程序,我需要为每匹马计算每年的分配总额(课程分配) 例如: 表:球场(比赛): [Id_课程:1,分配:200,日期:10/03/2012,idcheval:1] [Id_课程:2,分配:300,日期:11/07/2012,idcheval:1] [Id_课程:3,分配:700,日期:10/03/2013,idcheval:1] [Id_课程:4,分配:600,日期:10/03/2013,idcheval:1] 审计业务表: [2012年、2013年] 所以要

我用ionic 2开发了一个移动应用程序,我需要为每匹马计算每年的分配总额(课程分配)

例如: 表:球场(比赛):

[Id_课程:1,分配:200,日期:10/03/2012,idcheval:1]

[Id_课程:2,分配:300,日期:11/07/2012,idcheval:1]

[Id_课程:3,分配:700,日期:10/03/2013,idcheval:1]

[Id_课程:4,分配:600,日期:10/03/2013,idcheval:1]

审计业务表:

[2012年、2013年]

所以要这样显示:

2012年==>500

2013年==>1300

你能帮我吗

JSON

{
course_cheval: [
{
CourseHasCheval: {
id: "1294",
course_id: "408",
cheval_id: "182",
rang: "2",
temps: "5 L",
jockey_id: "23",
poids: "54",
part_jokey: "147.000",
entraineur_id: "6",
part_entraineur: "165.000",
propritaire: "TORGEMAN. F",
part_propritaire: "1650.000",
eleveur_id: "20",
part_eleveur: "825.000"
},
Course: {
id: "408",
date: "2013-12-22",
nom_du_prix: "ROUBAYIAT",
allocation: "7500",
hippodrome_id: "2",
jouree: "72",
categorie_id: "3",
distance: "1600",
nbre_partant: "8",
detail: " 5ème Course PRIX ROUBAYIAT (GR.3) Le 22 Déc 2013. Pouliches de 3 ans Pur Sang Arabe. 7.500 Dinars (4.125 - 1650 - 825 - 525 - 375) Primes (2.062.5 - 825 - 412.5 - 262,5) Entrée : 41 d,250 - Forfaits : 13 d,750 & 27 d,500 Pour pouliches de 3 ans de Pur Sang Arabe Poids 54 kg - Surcharge : 1 kg par course de G3 - 3 kg par course de G2, 5 kg par course de G1 - Surcharges cumulables. Distance : 1600 mètres environ. ",
video: "",
international: false,
etranger: "0"
},
Cheval: {
id: "182",
nom: "DAYJURA",
sexe: "2",
robe_id: "4",
ne: "2010",
race_id: "1",
code: "7957",
nom_p: "KERBELLA",
ne_p: "1992",
nom_m: "ISTIHBAB",
ne_m: "1996",
nom_pm: "CHEIKH EL ARAB",
ne_pm: "1990",
etat: "1",
eleveur_id: "20",
propritaire: "TORGEMAN. F",
photo: "",
export: "2000",
pays: "",
mise_service: null,
production: "0000"
},
},
{
CourseHasCheval: {
id: "583",
course_id: "187",
cheval_id: "182",
rang: "5",
temps: "5 L",
jockey_id: "23",
poids: "54",
part_jokey: "45.000",
entraineur_id: "6",
part_entraineur: "38.000",
propritaire: "TORGEMAN. F",
part_propritaire: "375.000",
eleveur_id: "20",
part_eleveur: "0.000"
},
Course: {
id: "187",
date: "2014-02-02",
nom_du_prix: "IKMEL",
allocation: "7500",
hippodrome_id: "2",
jouree: "6",
categorie_id: "3",
distance: "1600",
nbre_partant: "7",
detail: " 5ème Course PRIX IKMEL (GR.3) Le 02 Février 2014. Pouliches de 4 ans Pur Sang Arabe. 7.500 Dinars (4.125 - 1650 - 825 - 525 - 375) Primes (2.062.5 - 825 - 412.5 - 262,5) Entrée : 41 d,250 - Forfaits : 13 d,750 & 27 d,500 Pour pouliches de 4 ans de Pur Sang Arabe - Poids 54 kg - Surcharge : 1 kg par course de G3, 3 kg par course de G2 - 5 kg par course de G1 - Surcharges cumulables. Distance : 1600 mètres environ. ",
video: "",
international: false,
etranger: "0"
},
Cheval: {
id: "182",
nom: "DAYJURA",
sexe: "2",
robe_id: "4",
ne: "2010",
race_id: "1",
code: "7957",
nom_p: "KERBELLA",
ne_p: "1992",
nom_m: "ISTIHBAB",
ne_m: "1996",
nom_pm: "CHEIKH EL ARAB",
ne_pm: "1990",
etat: "1",
eleveur_id: "20",
propritaire: "TORGEMAN. F",
photo: "",
export: "2000",
pays: "",
mise_service: null,
production: "0000"
},
},
{
CourseHasCheval: {
id: "661",
course_id: "210",
cheval_id: "182",
rang: "1",
temps: "1.39''9/10",
jockey_id: "27",
poids: "55",
part_jokey: "330.000",
entraineur_id: "6",
part_entraineur: "330.000",
propritaire: "TORGEMAN. F",
part_propritaire: "3300.000",
eleveur_id: "20",
part_eleveur: "1650.000"
},
Course: {
id: "210",
date: "2014-03-09",
nom_du_prix: "OUID’AA",
allocation: "6000",
hippodrome_id: "2",
jouree: "15",
categorie_id: "4",
distance: "1400",
nbre_partant: "7",
detail: " 1ère Course PRIX OUID’AA (L.R) Le 09 Mars 2014. Pouliches & juments de 4 ans et plus Pur Sang Arabe. 6.000 Dinars (3.300 - 1.320 - 660 - 420 - 300) Primes (1.650 - 660 - 330 - 210) Entrée : 33 d,00 - Forfaits : 11 d,00 & 22 d,00 Pour pouliches et juments de 4 ans et plus de Pur Sang Arabe n’ayant pas gagné une course de G1 ou de G2 depuis le 01/01/2014 ni 10.500 DT depuis le 01/05/2014 - Poids 54 kg - Surcharge 1 kg par 2.000 DT, Décharge 2 kg pour celles n’ayant jamais gagné une course de groupe. Distance : 1400 mètres environ.",
video: "",
international: false,
etranger: "0"
},
Cheval: {
id: "182",
nom: "DAYJURA",
sexe: "2",
robe_id: "4",
ne: "2010",
race_id: "1",
code: "7957",
nom_p: "KERBELLA",
ne_p: "1992",
nom_m: "ISTIHBAB",
ne_m: "1996",
nom_pm: "CHEIKH EL ARAB",
ne_pm: "1990",
etat: "1",
eleveur_id: "20",
propritaire: "TORGEMAN. F",
photo: "",
export: "2000",
pays: "",
mise_service: null,
production: "0000"
},

},
{
CourseHasCheval: {
id: "687",
course_id: "219",
cheval_id: "182",
rang: "4",
temps: "3 L 1/2",
jockey_id: "27",
poids: "54",
part_jokey: "57.000",
entraineur_id: "6",
part_entraineur: "53.000",
propritaire: "TORGEMAN. F",
part_propritaire: "525.000",
eleveur_id: "20",
part_eleveur: "263.000"
},
Course: {
id: "219",
date: "2014-03-30",
nom_du_prix: "MEZIANA",
allocation: "7500",
hippodrome_id: "2",
jouree: "19",
categorie_id: "3",
distance: "1600",
nbre_partant: "5",
detail: " 2ème Course PRIX MEZIANA (GR.3) Le 30 Mars 2014. Pouliches de 4 ans Pur Sang Arabe. 7.500 Dinars (4.125 - 1650 - 825 - 525 - 375) Primes (2.062.5 - 825 - 412.5 - 262,5) Entrée : 41d, 250 – Forfaits : 13d, 750 & 27d, 500 Pour pouliches de 4 ans de Pur Sang Arabe - Poids 54 kg - Surcharge : 1 kg par course de G3, 3 kg par course de G2 - 5 kg par course de G1 - Surcharges cumulables. Distance : 1600 mètres environ.",
video: "",
international: false,
etranger: "0"
},
Cheval: {
id: "182",
nom: "DAYJURA",
sexe: "2",
robe_id: "4",
ne: "2010",
race_id: "1",
code: "7957",
nom_p: "KERBELLA",
ne_p: "1992",
nom_m: "ISTIHBAB",
ne_m: "1996",
nom_pm: "CHEIKH EL ARAB",
ne_pm: "1990",
etat: "1",
eleveur_id: "20",
propritaire: "TORGEMAN. F",
photo: "",
export: "2000",
pays: "",
mise_service: null,
production: "0000"
},

,

},
],
engagements: [
[
{
annee: "2014"
}
],
[
{
annee: "2013"
}
]
]
}
模板

<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>
映射并减少:

const table=[{
课程名称:1,
分配:200,
日期:2012年3月10日,
idcheval:1},
{ 
课程名称:1,
分配:200,
日期:2012年3月10日,
idcheval:1},{
课程名称:1,
分配:200,
日期:2014年3月10日,
idcheval:1},
{ 
课程名称:1,
分配:200,
日期:2012年3月10日,
idcheval:1}
];
var ret=table.map((x)=>({
分配:x.分配,
日期:x.date.split('/').slice(-1)[0]
}))
.sort((a,b)=>+(b.date)-+(a.date))
.减少((前、后)=>{
常量长度=前长度-1;
if(前[len]&&pre[len].date==当前日期){
pre[len]。分配+=当前分配;
返回预处理;
}
前[len+1]=当前;
返回预处理;
}, []);
用于(ret的常数x){
log(`${x.date}\t===>\t${x.allocation}`);

}
您更喜欢这个吗?还是我想在巧克力工厂找份工作?[这是我的照片,显示了错误][1]:
allocationSum: number;
// other variables

getIdCheval() {

  this.allocationSum = this.members.reduce((previous, current) => {
    return previous + parseInt(current.Course.allocation);
  }, 0);
}