【发布时间】:2017-10-06 16:40:44
【问题描述】:
我正在尝试获取“表”列 (getShotsTotal) 的总和,“forEach”在 Ionic1 中运行良好,但在 Ionic2 中失败,任何帮助将不胜感激。我认为可能需要一个标准的“循环”,但作为一个新手,我不确定正确的方法和代码。
HTML:
<tr class="row header" *ngFor = "let par of Course; let i=index" >
<td class="col">{{i +1}}</td>
<td class="col1">{{par.Index}}</td>
<td class="col">{{par.Par}}</td>
<td class="col2">{{getPoints(par)}}</td>
<td class="col">{{getShots()}}</td>
<td class="col3" ><select [(ngModel)]="par.sel"
(change)="onChangeScore(par.sel)"><option *ngFor= "let s of items" >{{s}}
</option></select></td>
</tr>
<tr class="row" style="height:32px">
<td class="col">Total</td>
<td class="col"></td>
<td class="col"></td>
<td class="col"></td>
<td class="col">{{getTotalShots()}}</td>
<td class="col"></td>
</tr>
TS:
getShots(par) {
let val = this.selectedHcp - par.Index;
if (val > 17.4) {
return 2;
} else if (val >= -0.5) {
return 1;
} else if (val < -0.5) {
return 0;
}
};
getTotalShots = function () {
if (!this.Par) { return 0;
}
var total = 0;
angular.forEach(this.Par, function (item, index) {
total = total + (this.getShots(item) || 0);
});
return total;
};
【问题讨论】:
标签: angular typescript angular2-template