3 回答
TA贡献1827条经验 获得超8个赞
你可以用一个函数来完成,并用 ES6 特性调用你的列表。
const fundList = [{
"success": "true",
"id": "fund",
"options": "others",
"fee": 3,
"tax": 0.3,
"amount": 2000
},
{
"success": "true",
"id": "fund",
"options": "others",
"fee": 3,
"tax": 0.3,
"amount": 2000
}]
const transList = [{
"success": "true",
"id": "trans",
"options": "service",
"fee": 2,
"tax": 0.4,
"amount": 1000
},
{
"success": "true",
"id": "trans",
"options": "service",
"fee": 2,
"tax": 0.4,
"amount": 1000
}]
function calc(e, rate, addFee) {
const netFee = e.fee + e.tax;
const amountwithfee = e.amount + netFee;
return {
rate: rate,
addfee: addFee ? addFee : null,
netFee,
amountwithfee,
total: amountwithfee * rate
}
}
const newTransList = transList.filter(e => e.success === 'true').map(e => calc(e, 2));
console.log(newTransList);
const newFundList = fundList.filter(e => e.success === 'true').map(e => calc(e, 4, 10));
console.log(newFundList);
添加回答
举报