要对 formlist.ADList 中的 amount 求和,你可以使用 JavaScript 的 reduce 函数。以下是一个示例代码:
getList() {
this.httpRequest({
url: "/ReimbursementAskProcess/Get?ProcessInstanceId=" + this.PID,
method: 'GET',
success: (data) => {
this.formlist = data.data.Data;
// 对ADList中的amount求和
const totalAmount = this.formlist.ADList.reduce((sum, item) => sum + item.amount, 0);
console.log("总金额:", totalAmount);
}
});
}
在上面的代码中,reduce 函数会迭代 this.formlist.ADList 中的每个元素,将它们的 amount 属性累加起来。累加的初始值为 0。最后,totalAmount 变量包含了求和的结果。你可以根据需要将这个总金额用于其他逻辑或显示。