在 for 循环中,我正在获取这些数据这个值来自 EXT js 商店。 var sum = results.rows.item(i).Count;
console.log(sum);结果,它显示2563我需要在一个变量中计算这个总和。任何人都可以回答这个问题,请。这是一个 javascript 函数。
2 回答
繁华开满天机
TA贡献1816条经验 获得超4个赞
您可以使用该reduce功能:
let array = [2,5,6,3];
// will reduce an array to a single variable.
let sum = array.reduce((collector, num) => {
// the collector is kept for each iteration
return collector += num;
}, 0 /* initial value is 0 */);
console.log(sum)
慕容森
TA贡献1853条经验 获得超18个赞
只需在 store 对象上使用 ExtJS 的内置函数:
myStore.sum('items'); // assuming 'items' is the field you need to sum
https://docs.sencha.com/extjs/7.0.0/classic/Ext.data.Store.html#method-sum
如果是分组商店,您还可以获得分组总和。
添加回答
举报
0/150
提交
取消