我在这里有数据数组
"item_tabel": [
{
"method": {
"select_method": 6,
},
"innovation": {
"select_innovation": 2,
},
}
],如何使用sum计算?
这是我的电脑
subtotalRow() {
return this.$store.state.item_tabel.map((item,i) => {
return Number(item.method.select_method * item.innovation.select_innovation)
//how to sum (item.method.select_method + item.innovation.select_innovation)
});
},我的表中的示例
No | method | inov | total
1 | 6 | 2 | (6+2 = 8) //calculate
2 | 2 | 2 | 4 //calculate 如果使用运算符*有效,而使用+无效
非常感谢
发布于 2021-10-29 10:20:55
如果您真的想添加6和2
当然,你所需要做的就是你在评论行中写的东西?
subtotalRow() {
return this.$store.state.item_tabel.map(
(item,i) => (item.method.select_method + item.innovation.select_innovation)
);
},发布于 2021-10-29 10:53:10
这对你来说应该是可行的;
由于Array.map()需要回调函数,因此函数体应该用大括号'{}‘括起来
subtotalRow() {
return this.$store.state.item_tabel.map(
(item,i) => {item.method.select_method + item.innovation.select_innovation}
);
},https://stackoverflow.com/questions/69767094
复制相似问题