日期:2014-05-17  浏览次数:20754 次

ext 的一段代码,是关于变量值的传递问题。请教各位大侠
Ext.MyForm=Ext.extend(Ext.form.FormPanel ,{
xtype:"formpanel",
title:"费用核算结果",
labelWidth:100,
labelAlign:"left",
layout:"form",
width:800,
padding:"10px",
autoHeight:true,
initComponent: function(){
var store = new Ext.data.JsonStore({
url: 'InvoicesProvider.jsp',
root: 'result',
fields:Ext.data.Record.create([
{name: 'id', type: 'string'},
{name: 'type', type: 'string'},
{name: 'invoiceNo', type: 'string', allowBlank:false},
{name: 'amount', type: 'number', allowBlank:false},
{name: 'info', type: 'string', allowBlank:false},
{name: 'ys_zt', type: 'string', allowBlank:false},
{name: 'ys_rq', type: 'date', dateFormat:'Y-m-d H:i:s'}
])
//plugins:[new Ext.ux.grid.RowEditor()]
});
store.baseParams["runId"] = '${runId}';//加载数据
var str="";

//Ext.Msg.alert('提示', str);
var grid = new Ext.grid.EditorGridPanel({
height:180, store:store, 
cm:new Ext.grid.ColumnModel([
{header:'序号', dataIndex:'id', sortable:true, width:30},
{header:'费用名称', dataIndex:'type', sortable:true, width:70},
{header:'发票号码',dataIndex:'invoiceNo', width:120},
{header:'金额',dataIndex:'amount', width:90, xtype:'numbercolumn', align:'right'},
{header:'说明',dataIndex:'info', width:200},
{header:'成本承担中心',dataIndex:'ys_zt'},
{header:'成本日期', dataIndex:'ys_rq', xtype:'datecolumn', format:'Y-m-d'}
]),

fbar:[


"费用小计:str","合计费用:${reimburse_amount}, 其中抵冲借款额:${amount_for_borrow}, 现金额:${amount_for_cash}"

]
});
store.load({callback:function(r, options, success) {
if (!success) {
return;
}
var str="";
var arr = {};
for (var i in r) {
var record = r[i];//行
if(record.get == null){
continue;
}
var key = record.get("type");
var amount = arr[key];
if (amount == null) {
amount = 0;
}
amount += record.get("amount");
arr[key] = amount;
}
for (var i in arr) {
str += i + "=" + arr[i] + ", ";
}

}});
this.items=[
{
xtype:"textarea",
name:"Cost_Accounting_Result",
fieldLabel:"核算结果",
anchor:"100%",
allowBlank:false
},
{
xtype:"fieldset",
title:"报销明细",
layout:"form",
items:[
grid
]
}
]
Ext.MyForm.superclass.initComponent.call(this);
}
})

上面的代码我怎么把store.load里面得到的str的值传递到fbar里面的str去?

------解决方案--------------------
定义个全局变量 先执行store.load的方法 为变量赋值
然后在fbar中引用