亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在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 關注
  • 309 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號