ProductGridPanel 那个rowselect的事件那样用会照成死循环吗

见一下代码 那个rowselect的事件那样用会照成死循环吗

/********创建FormPanel*******/
ProductFormPanel = Ext.extend(Ext.form.FormPanel,{
constructor:function(){
ProductFormPanel.superclass.constructor.call(this,
{
labelWidth:45,
defaultType:'textfield',
defaults:{anchor:'90%'},
baseCls:'x-plain',
items:[
{fieldLabel:'姓名',name:'name'},
{fieldLabel:'年龄',name:'age'},
{
fieldLabel:'性别',
hiddenName:'sex',
xtype:'combo',
mode:'local',
displayField:'sex',
readOnly:true,
triggerAction:'all',
value:'男',
store:new Ext.data.SimpleStore({
fields:['sex'],
data:[['男'],['女']]
})
}
]
})
},
reset:function(){
this.getForm().reset();
},
getValue:function(){
if(this.getForm().isValid()){
return new Ext.data.Record(this.getForm().getValues());
}else{
throw Error('表单未能通过!');
}
},
setValue:function(_r){
this.getForm().loadRecord(_r);

}
});
/*******创建Windows*********/
ProductWindows = Ext.extend(Ext.Window,{
form: new ProductFormPanel(),
constructor:function(){
this.form = new ProductFormPanel();
ProductWindows.superclass.constructor.call(this,
{
plain:true,
width:300,
modal:true,
items:this.form,
closeAction:'hide',
buttons:[
{
text:'确定',
handler:this.onSubmitClick,
scope:this
},
{
text:'取消',
handler:this.onCancelClick,
scope:this
}]
}
);
this.addEvents('submit');
},
close:function(){
this.form.reset();
this.hide();
},
onCancelClick:function(){
this.close();
},
onSubmitClick:function(){
try{

this.fireEvent('submit',this,this.form.getValue());
this.close();
}catch(_err){
return;
}
}
});
/*******创建InsertWin*******/
InsertProductWin = Ext.extend(ProductWindows,{
title:'添加产品'
});
/*******创建UpdateWin*******/
UpdateProductWin = Ext.extend(ProductWindows,{
load:function(_r){this.form.setValue(_r);},
title:'修改产品'
});
/*******创建GridPanel*******/
var data = [{name:'张三',sex:'男',age:18},{name:'李四',sex:'女',age:20}];
var store = new Ext.data.JsonStore({
data:data,
autoLoad:true,
fields:['name','age','sex']
});
var cm = new Ext.grid.ColumnModel([
{dataIndex:'name',header:'姓名',sortable:true},
{dataIndex:'sex',header:'性别',sortable:true},
{dataIndex:'age',header:'年龄',sortable:true}
]);
ProductGridPanel = Ext.extend(Ext.grid.GridPanel,{
insertwin:new InsertProductWin(),
updatewin:new UpdateProductWin(),
constructor:function(){
ProductGridPanel.superclass.constructor.call(this,{
cm:cm,
region:'center',
height:300,
store:store,
border:false,
//这个地方这样用是死循环了吗
sm:new Ext.grid.RowSelectionModel({
singleSelect:true,
listeners:{
'rowselect':{
fn:function(_sel,_index,_r){this.fireEvent('rowselect',_r)},
scope:this
}
}
}),
title:'测试',
tbar:[
{
text:'添加记录',
handler:function(){this.insertwin.show();},
scope:this
},
'-',
{
text:'修改记录',
handler:function(){
// this.updatewin.show();
// var r = this.getSelected();
try{
this.updatewin.show();
this.updatewin.load(this.getSelected());
}catch(_err){
alert(_err.description);
}
},
scope:this
}]
}),
this.insertwin.on('submit',this.onInsertWinSubmit,this);
this.addEvents('rowselect');
},
getSelected:function(){
var _sm = this.getSelectionModel();
if(_sm.getCount()==0)
{
throw Error('请选择一条记录!');
}
return _sm.getSelected();
},
onRowSelect:function(_sel,_index,_r){
this.fireEvent('rowselect',_r);
},
insert:function(_r){
alert(Ext.util.JSON.encode(_r));

this.getStore().add(_r);
},
onInsertWinSubmit:function(_win,_r){

this.insert(_r);
}
});


Ext.onReady(function(){
var grid = new ProductGridPanel();
var view = new Ext.Viewport({
renderTo:Ext.getBody(),
items:[grid]
});
});



如何能把ToolBar也封装成一个类呀!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值