为了账号安全,请及时绑定邮箱和手机立即绑定

如何在ext js中的for循环内获取数组中的总值总和

如何在ext js中的for循环内获取数组中的总值总和

九州编程 2021-12-02 15:56:09
在 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)


查看完整回答
反对 回复 2021-12-02
?
慕容森

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

如果是分组商店,您还可以获得分组总和。


查看完整回答
反对 回复 2021-12-02
  • 2 回答
  • 0 关注
  • 284 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信