我的输入是一个json对象,格式如下:
{
"baskets": [{
"id": 127,
"name": "name 1",
"kpIs": [{
"id": 419,
"name": var a1, "incentive": 0, "target": "0", "actual": 0, "description": null
}, {
"id": 420,
"name": var a2, "incentive": 0, "target": "0", "actual": 0, "description": null
}],
"percentage": 0
}, {
"id": 128,
"name": "name 2",
"kpIs": [{
"id": 421,"name": "var b1","incentive": 0,"target": "0","actual": 0, "description": null
}, {
"id": 422, "name": "var b2","incentive": 0,"target": "3", "actual": 0, "description": null
}, {
"id": 423, "name": " var b3","incentive": 0,"target": "5.6","actual": 0,"description": null
}, {
"id": 424,"name": " var b4", "incentive": 0, "target": "2", "actual": 0, "description": null
}],
"percentage": 0
}],
"id": 23,
}
我想计算每个嵌套对象的总计(目标、激励和实际)以及对象的总体总计。我已将对象绑定到表:
.
<table class="table table-responsive table-bordered table-striped w-100%">
<thead>
<tr>
<th data-label="KPI Basket" scope="col">KPI Basket</th>
<th data-label="KPIs" scope="col">KPIs</th>
<th data-label="Tgt figures" scope="col">Target</th>
<th data-label="Tgt figures" scope="col">Actual</th>
<th data-label="Incentive" scope="col">Incentive</th>
<th data-label="% of Total" scope="col">Total</th>
</tr>
</thead>
<tbody *ngFor="let data of document.baskets; let i = index">
<tr style="margin: auto;" *ngFor="let obj of data.kpIs">
<td>{{ data.name }}</td>
<td>{{ obj.name }}</td>
<td>{{ obj.target }}</td>
<td>
<input
type="number"
[(ngModel)]="obj.actual"
name="actual{{j}}"
class="form-control"
(change)="performOperations(obj.actual, obj.target, obj.incentive )"
/>
</td>
<td>{{ obj.incentive }}</td>
<td>
<input
type="number"
[(ngModel)]="individualTotal"
name="individualTotal{{j}}"
class="form-control"
/>
</td>
</tr>
<tr>
<th data-label="KPI Basket" scope="row"></th>
<strong> <td data-label="KPIs">Sub-total</td></strong>
<td data-label="Incentive">{{ subTotal }}</td>
<td data-label="% of Total"></td>
<td data-label="Tgt figures"></td>
<td data-label="Tgts"></td>
</tr>
</tbody>
<tbody>
<tr>
<strong>
<tr data-label="KPIs">
Total
</tr></strong
>
<td data-label="KPI Basket" scope="row"></td>
<td data-label="Incentive"></td>
<td data-label="% of Total"></td>
<td data-label="Tgt figures">35</td>
<td data-label="Tgts">35</td>
</tr>
</tbody>
</table>
“小计”字段应为嵌套对象名称1和名称2添加总计。然后,“总计”字段应为对象添加总计。我怎样才能做到这一点?
2条答案
按热度按时间72qzrwbm1#
根据评论进行计算,
小计用于实际列,该列在文本框中输入。那么总数就是实际的*激励–user9913710
mm9b1k5b2#
您可能希望通过以下方式调用。减少KPI篮数组(例如奖励):
如果您同时想要两个金额(奖励和合计),您可以:
在我看来,第一个更清楚。您可以修改它以传递要计算总和的对象键。