一、关于Ext.window的隐藏(hide)和销毁(close)的问题
在这两天的开发中我碰到这样一个问题,在第一次打开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();
- }
- <pre name="code" class="java">
- <pre></pre>
- <p>修改后的:</p>
- <pre name="code" class="java">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,
- <span style="color:#FF6666;"> closeAction: 'close', //close 关闭 hide 隐藏</span>
- animEl:'btnadd',
- title:"查看客户客走访信息",
- buttons : [this.ButtonNewAdd, this.ButtonClose],
- items : this.showTabPanel
- });
- this.win.show();
- }
- this.closeWin = function(){
- this.parentForm.store.reload();
- <span style="color:#FF6666;">this.win.close();</span>
- }
- </pre><br>
- 这样修改后 就可以正常的打开了。<img alt="大笑" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif">
- <p><br>
- </p>
- <p><span style="font-size:16px">ps:注意红色部分的代码,及每段代码的位置.</span></p>
- <p>本人认为出现此种情况的原因:改前 各组件对象只实例化了一次,window关闭后再打开时无法调到该组件,导致window无法显示</p>
- <p>而将组件放到show方法里面后,每次调用show方法时组件都会被实例化一次,因此能能够正常显示。<br>
- </p>
- <br>
- <p><br>
- </p><table border="1" cellpadding="1" cellspacing="1" height="63" width="870">
- <tbody>
- <tr>
- <td> </td>
- <td> </td>
- </tr>
- <tr>
- <td> </td>
- <td> </td>
- </tr>
- <tr>
- <td> </td>
- <td> </td>
- </tr>
- </tbody>
- </table>
- <br>
- <p></p>
- <pre></pre>
- <pre></pre>
- <pre></pre>
- <div style="padding-top:20px">
- <p style="font-size:12px;">版权声明:本文为博主原创文章,未经博主允许不得转载。</p>
- </div>
- </pre>
二、多层iframe嵌套页面中关才最外层的Ext Window
var windowElement = parent.Ext.fly(window.frameElement).up('div.x-window');
parent.Ext.getCmp(windowElement.id).close();
function closewindow() {
var currentWin = window;
while (top != currentWin) {
var prentExt = currentWin.parent.Ext;
var fElement = prentExt.get(currentWin.frameElement);
var windowElement = fElement.up('div.x-window');
if (windowElement) {
var winId = windowElement.id;
var extWin = prentExt.getCmp(winId);
extWin.close();
return true;
} else {
currentWin = currentWin.parent;
}
}
alert('窗口关闭错误');
return false;
}