计算 angular 中的列总数
Calculate column quantity total in angular
我有一个包含数量字段的对象数组。我希望在 table.
的审查屏幕上从数组中总计一个字段
我有一组管理对象字段,我要计算的是 'quantity field'.
<tr class="primary" *ngFor="let medication of sachets">
<td>{{medication.administration.quantity}}</td>
<td>
{{medication.medicationName}}
<p class="instructions">{{medication.additionalInstructions}}</p>
</td>
</tr>
在 table 中,我正在使用 angulars .length
计算条目的长度
我正在计算数量数组的总数。
找到过滤和添加值的解决方案。我使用 .map 函数创建了一个数量值数组,并使用 .reduce 将它们相加得到所需的总数。
totalFunction() {
const initialValue = 0;
this.totalQuantity = this.administered.map
(item => item.administration.quantity).reduce(
(previousValue, currentValue) => previousValue + currentValue,
initialValue);
console.log(this.totalQuantity);
}
我有一个包含数量字段的对象数组。我希望在 table.
的审查屏幕上从数组中总计一个字段我有一组管理对象字段,我要计算的是 'quantity field'.
<tr class="primary" *ngFor="let medication of sachets">
<td>{{medication.administration.quantity}}</td>
<td>
{{medication.medicationName}}
<p class="instructions">{{medication.additionalInstructions}}</p>
</td>
</tr>
在 table 中,我正在使用 angulars .length
计算条目的长度我正在计算数量数组的总数。
找到过滤和添加值的解决方案。我使用 .map 函数创建了一个数量值数组,并使用 .reduce 将它们相加得到所需的总数。
totalFunction() {
const initialValue = 0;
this.totalQuantity = this.administered.map
(item => item.administration.quantity).reduce(
(previousValue, currentValue) => previousValue + currentValue,
initialValue);
console.log(this.totalQuantity);
}