在这两天的开发中我碰到这样一个问题,在第一次打开window时数据正常,但是第二次及以后打开时现实的额数据任然是第一次打开的数据。
经查找发现此时window调用的关闭方式是hide而不是close,即每次关闭时实质上是没有关闭的只是把window隐藏了而已,此时只要把关闭方法用close即可,而且把closeAction:'close'这样配置即可。
但是此时问题又发生了,此时window打开一次后就无法打开了
代码:
//关闭按钮
this.ButtonClose =new Ext.Button({
text:'关闭',
id:'ButtonClose',
width:200
});
//新增按钮
this.ButtonNewAdd =new Ext.Button({
text:'新增走访记录',
id:'ButtonNewAdd',
width:200
});
//******必须把new window的操作放在这个 show方法里面 否则执行close操作后第二次就无法打开*****
this.win = new Ext.Window({
id:'checkInfoWin',
layout:'fit',
width:800,
height:500,
modal : true,
draggable : true,
resizable : false,
closeAction: 'close', //close 关闭 hide 隐藏
animEl:'btnadd',
title:"查看客户客走访信息",
buttons : [this.ButtonNewAdd, this.ButtonClose],
items : this.showTabPanel
});
this.show = function(id,name){
this.win.show();
}
this.closeWin = function(){
this.parentForm.store.reload();
this.win.close();
}
修改后的:
this.show = function(id,name){ //关闭按钮 this.ButtonClose =new Ext.Button({ text:'关闭', id:'ButtonClose', width:200 }); //新增按钮 this.ButtonNewAdd =new Ext.Button({ text:'新增走访记录', id:'ButtonNewAdd', width:200 }); this.win = new Ext.Window({ id:'checkInfoWin', layout:'fit', width:800, height:500, modal : true, draggable : true, resizable : false, closeAction: 'close', //close 关闭 hide 隐藏 animEl:'btnadd', title:"查看客户客走访信息", buttons : [this.ButtonNewAdd, this.ButtonClose], items : this.showTabPanel }); this.win.show(); } this.closeWin = function(){ this.parentForm.store.reload(); this.win.close(); }
这样修改后 就可以正常的打开了。
ps:注意红色部分的代码,及每段代码的位置.
本人认为出现此种情况的原因:改前 各组件对象只实例化了一次,window关闭后再打开时无法调到该组件,导致window无法显示
而将组件放到show方法里面后,每次调用show方法时组件都会被实例化一次,因此能能够正常显示。