JScript codeapp.ux.AggregateStore=Ext.extend(Ext.data.GroupingStore,{
summaryField:null,
constructor:function(config){
Ext.apply(this,config);
app.ux.AggregateStore.superclass.constructor.call(this);
this.on('load',this.aggregate,this);
},
aggregate:function(){
var rec=null;
this.each(function(record){
if(rec==null||rec.data[this.groupField]!=record.data[this.groupField]){
/针对特定项目的处理
if(record.data.salePrice==undefined||record.data.salePrice==0){
record.data.salePrice=record.data.price;
}
record.data.profit=(record.data.salePrice-record.data.price)*record.data.quantity;
//通用代码
rec=record;
return;
}
if(rec.data[this.groupField]==record.data[this.groupField]){
/针对特定项目的处理
var currentTotal=record.data.total;
record.data.profit=(record.data.salePrice-record.data.price)*record.data.quantity;
record.data.profit+=rec.data.profit;
record.data[this.summaryField]+=rec.data[this.summaryField];
record.data.quantity+=rec.data.quantity;
/通用代码
this.remove(rec);
rec=record;
}
},this);