2013-05-17 36 views
1

我有要求將存儲字段值的值和總和進行分組的要求。當總結我得到NaN的價值時。我從json響應中獲得null值。任何人都可以告訴我如何用extjs中的零代替零?有沒有其他方法可以在總結場地值時避開Nan?如何使用sum函數處理存儲區中的空值

clientDistributionStore.group(groupField); 
curJANObj= clientDistributionStore.sum('curJAN',true); 

我得到空的一些「curJAN」值,所以我得到楠錯誤

回答

0

我得到它通過record.set功能設定值0空

0

另一種方法是添加一個新的「轉換」(我寧願稱之爲「計算」)字段到您的模型:

fields: [ 
    { name: 'curJan', type: 'int' }, 
    { 
    name: 'curJanNotNull', type: 'int', 
    convert: function(val, row) { 
     return row.curJan !== null ? row.curJan : 0; 
    } 
    } 
] 

... 

var janSum = clientDistributionStore.sum('curJanNotNull', true); 
0

我有類似的問題。我這樣解決了它。因爲現在它也把空字符串爲0。你可以把它修改自己的需要,但你不能返回空值

clientDistributionStore.group(Ext.create('Ext.util.Grouper', { 
    property: groupField, 
    getGroupString: function (instance) { 
     return instance.get(this.property) || 0; 
    } 
})); 

curJANObj= clientDistributionStore.sum('curJAN',true); // return ex. {0: 100, 'John Smith': 1000} 

getGroupString功能可以實現其他的方式。

它適用於ExtJS 4.2.1