gpt4 book ai didi

javascript - Ext.window 在父类窗口的关闭按钮上覆盖子类中的销毁

转载 作者:行者123 更新时间:2023-11-28 00:44:00 32 4
gpt4 key购买 nike

我的代码中有一个 ext.window,它具有默认的保存和关闭按钮。在关闭按钮上单击我隐藏窗口:

Ext.define('MyPack.template.TemplateWindow', {
extend : 'Ext.Window',

id: 'templateEditorWindow',
closeAction: 'hide',
autoScroll: false,

createTemplateEditor : function() {
// some code
},

initComponent : function() {

this.createTemplateEditor();

Ext.applyIf(this, {
layout : 'border',
modal : true
});

this.items = [ this.templateEditor ];
this.buttons = [
{ text : '#{msgs.button_save}',
window : this,
handler : function () {
if(this.window.templateEditor.save()) {
this.window.hide();
}
}
},
{ text : '#{msgs.button_close}',
cls : 'secondaryBtn',
window : this,
handler : function( ){
this.window.hide();
}
}
];

this.callParent(arguments);
},

});

我还有一个窗口延伸到窗口上方。

Ext.define('MyPack.template.RestfulTemplateWindow', {
extend : 'MyPack.template.TemplateWindow',

createTemplateEditor : function() {
// some code
}
});

我正在创建这个子类。窗口已正确创建。但我想重写关闭按钮的处理函数。关闭时它应该会销毁。

我怎样才能覆盖它?

最佳答案

您可以定义closeAction在 window 上

closeAction : String The action to take when the close header tool is clicked:

destroy : remove the window from the DOM and destroy it and all descendant Components. The window will not be available to be redisplayed via the show method.

hide : hide the window by setting visibility to hidden and applying negative offsets. The window will be available to be redisplayed via the show method. Note: This behavior has changed! setting does affect the close method which will invoke the approriate closeAction.

Defaults to: 'destroy'

因此无需覆盖任何内容。

编辑>>记住调用close()而不是hide()!

{ 
text : '#{msgs.button_save}',
window : this,
handler : function () {
if(this.window.templateEditor.save()) {
this.window.close(); // call close!
}
}
},
{ text : '#{msgs.button_close}',
cls : 'secondaryBtn',
window : this,
handler : function( ){
this.window.close(); // call close!
}
}

编辑

免责声明:以下方法只是一种解决方法

Ext.define('MyPack.template.RestfulTemplateWindow', {
extend : 'MyPack.template.TemplateWindow',
closeAction: 'destroy', // redefine th close action
initComponent: function() {
// all values set would be overrided by the parent
this.callParent(arguments);
// identify the buttons somehow
this.on('beforehide',function(w){w.close();return false;},this);
}
});

关于javascript - Ext.window 在父类窗口的关闭按钮上覆盖子类中的销毁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27615702/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com