毁坏窗户

发布于 2025-01-07 21:49:39 字数 998 浏览 0 评论 0原文

我正在使用ExtJs4。

new Ext.Window({
    id: token + '_window',
    animateTarget: token + '_taskbar',  //Button id
    height: 300,
    width: 300,
    title: name,
    maximizable: true,
    minimizable: true,
    iconCls: 'basketball-small-icon',
    html: 'This is the <b>' + name + '</b> window',
    listeners: {
        'beforeclose': onWindowClose,
        'minimize': function(){ this.hide(); }
    }

请注意与动画目标关联的按钮。 这里 onWindowClose 被定义为

function onWindowClose(t){
var token = t.id.split('_')[0];
var taskBarItemId = token + '_taskbar';

Ext.getCmp(taskBarItemId).destroy(); //Destroying the button
t.destroy();  //Destroying the window
}

这里我想删除窗口和关联的按钮。 每次关闭窗口时,我有两种选择,如下所示,

  • 我可以同时销毁按钮和窗口,但有时我无法再次打开窗口。我认为这与按钮链接到窗口的“animateTarget”这一事实有关。因为当我删除这个属性时,效果很好。
  • 我可以使用 t.close() 而不是 t.destroy(),但它会变得递归。如何调用基本的 close 方法?

每次单击图标时都销毁窗口并使用“新”创建窗口是个好主意吗? close() 和 destroy() 方法有什么区别?

I am using ExtJs4.

new Ext.Window({
    id: token + '_window',
    animateTarget: token + '_taskbar',  //Button id
    height: 300,
    width: 300,
    title: name,
    maximizable: true,
    minimizable: true,
    iconCls: 'basketball-small-icon',
    html: 'This is the <b>' + name + '</b> window',
    listeners: {
        'beforeclose': onWindowClose,
        'minimize': function(){ this.hide(); }
    }

Note the button to which the animate target is associated.
Here the onWindowClose is defined as

function onWindowClose(t){
var token = t.id.split('_')[0];
var taskBarItemId = token + '_taskbar';

Ext.getCmp(taskBarItemId).destroy(); //Destroying the button
t.destroy();  //Destroying the window
}

Here I want to remove the window and the associated button.
Everytime I close the window, I have two choices as below

  • I can destroy both the button and the window but sometimes I can't open the window again. I think this has something to do with the fact that the button is linked to window's 'animateTarget'. Because when I remove this property, this works fine.
  • I can use t.close() instead of t.destroy(), but it becomes recursive. How can I call the base close method?

Is it a good idea to destroy the window everytime and create using 'new' whenever the icon is clicked?
What is difference between close() and destroy() methods?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

π浅易 2025-01-14 21:49:39

如果我理解得很好,您想重用该窗口,并显示不同的内容。
因此,您应该只创建一个窗口,通过更新 html 内容并在此窗口上调用 show() 来重用该窗口。
要执行此操作,您需要添加属性 closeAction:'hide'。这样,当单击关闭按钮时,您的窗口就不会被破坏。

test = new Ext.Window({
    id: token + '_window',
    animateTarget: token + '_taskbar',
    height: 300,
    width: 300,
    title: name,
    maximizable: true,
    minimizable: true,
    closeAction: 'hide',
    iconCls: 'basketball-small-icon',
    html: 'This is the <b> imad </b> window',
    listeners:{
        'beforehide':function(win){
            Ext.getCmp(win.animateTarget).hide();
        }
    }
});

然后,将此侦听器添加到按钮中:

    listeners:{
        'click':function(){
            var token = t.id.split('_')[0];
            var targetWindow = Ext.getCmp('token + '_window);
            targetWindow.body.dom.innerHtml = 'Your new html !';
            targetWindow.show();
        }
    }

If I understand well, you want to reuse the window, with a different content.
So, you should create only one window, that you reuse by updating the html content and calling show() on this window.
To perform that, you need to add the property closeAction:'hide'. This way, your window won't be destroyed when clicking on the close button.

test = new Ext.Window({
    id: token + '_window',
    animateTarget: token + '_taskbar',
    height: 300,
    width: 300,
    title: name,
    maximizable: true,
    minimizable: true,
    closeAction: 'hide',
    iconCls: 'basketball-small-icon',
    html: 'This is the <b> imad </b> window',
    listeners:{
        'beforehide':function(win){
            Ext.getCmp(win.animateTarget).hide();
        }
    }
});

Then, you add this listener to your buttons :

    listeners:{
        'click':function(){
            var token = t.id.split('_')[0];
            var targetWindow = Ext.getCmp('token + '_window);
            targetWindow.body.dom.innerHtml = 'Your new html !';
            targetWindow.show();
        }
    }
把人绕傻吧 2025-01-14 21:49:39

您不必调用 destroy(),因为一旦窗口关闭,它就会自动销毁。
请参阅 Ext.Window 的 api
并且不要在 beforeclose 处理程序中调用 close() ,因为它已经即将关闭。

我认为只要您想创建一个窗口并关闭它,您就可以使用“new”,或者单击关闭标题工具(右上角)或调用其 close() 方法。不用担心破坏。 Ext 会做到这一点。

close() 和 destroy() 之间的主要区别是 close 触发 'beforeclose' 事件,并根据配置选项 'closeAction' 决定是否关闭窗口或隐藏它。如果决定关闭,将调用 destroy()。

编辑:
尝试以下

function onWindowClose(t){
    var token = t.id.split('_')[0];
    var taskBarItemId = token + '_taskbar';

    Ext.getCmp(taskBarItemId).destroy(); //Destroying the button
    //t.destroy();  //Remove this statement.
    return true;
}

编辑2:删除最小化侦听器

listeners: {
    'beforeclose': onWindowClose//,
     //'minimize': function(){ this.hide(); }
}

You don't have to call destroy() since once the window is closed, it is automatically destroyed.
See api of Ext.Window.
And do not call close() in your beforeclose handler since it's already about to close.

I think you can use 'new' whenever you want to create a window and close it either click on the close header tool(top right) or call its close() method. Don't worry about destroy. Ext will do it.

The main difference between close() and destroy() is close fires 'beforeclose' event and decide whether to close the window or hide it based on config option 'closeAction'. If it decides to close, destroy() will be called.

EDIT:
try the following

function onWindowClose(t){
    var token = t.id.split('_')[0];
    var taskBarItemId = token + '_taskbar';

    Ext.getCmp(taskBarItemId).destroy(); //Destroying the button
    //t.destroy();  //Remove this statement.
    return true;
}

EDIT2: Remove minimize listener

listeners: {
    'beforeclose': onWindowClose//,
     //'minimize': function(){ this.hide(); }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文