我想添加工作项目成本,但显示原始值。
示例:
item[1].cost =2 ,item[2].cost = 2 ..
当我添加第3 item[3].cost = 8
个Total = 228
时。我想添加SUM,怎么做?我想要总=12
。
addWorkItem() {
this.current_job.work_items.push(this.current_workitem);
this.Total = 0;
for (var i = 0, len = this.current_job.work_items.length; i < len; i++) {
this.Total += this.current_job.work_items[i].cost;
}
this.current_workitem = {};
}
答案 0 :(得分:2)
那是因为你要对数字进行连接,而不是添加。
addWorkItem() {
this.current_job.work_items.push(this.current_workitem);
this.Total = 0;
for (var i = 0, len = this.current_job.work_items.length; i < len; i++) {
this.Total += parseFloat(this.current_job.work_items[i].cost);
}
this.current_workitem = {};
}