gpt4 book ai didi

Extjs:覆盖特定监听器

转载 作者:行者123 更新时间:2023-12-02 04:29:01 25 4
gpt4 key购买 nike

我有一个窗口组件,我正在扩展它以创建不同的窗口。现在,close()hide() 监听器函数全面相同,但 afterrender() 随每个实例而变化。

所以我有这样的东西:

Ext.define('abc.xyz.BaseWindow', {
extend : "Ext.Window",
listeners: {
hide: function(el, eOpts){
console.log('hide');
},
close: function(el, eOpts){
console.log('close');
}
}
});

还有:

Ext.define('abc.xyz.MyWindow', {
extend : "abc.xyz.BaseWindow",
listeners: {
afterrender: function(el, eOpts){
console.log('afterrender');
}
}
});

但是,整个 listeners 对象会被覆盖,并且 hide()close() 永远不会被调用。除了在每个扩展窗口中指定 hide()close() 之外,还有什么办法可以解决这个问题吗?

最佳答案

您可以在窗口中定义函数,调用它们并在窗口中覆盖它们,如下所示:

Ext.define('abc.xyz.BaseWindow', {
extend : "Ext.Window",
onHide: function(){
console.log('hide');
},
onShow: function(el, eOpts){
console.log('close');
},
onAfterRender: function(el, eOpts){
console.log('first after render');
},

initComponent: function () {
var me = this;

Ext.applyIf(me, {
listeners: {
hide: me.onHide,
show: me.onShow
afterrender: me.onAfterRender
}
});

me.callParent(arguments);
}
});

还有:

Ext.define('abc.xyz.MyWindow', {
extend : "abc.xyz.BaseWindow",
onAfterRender: function(el, eOpts){
console.log('second after render');
}
});

或者,如果您在基类中没有后渲染,您只需添加一个监听器,就像 Evan Trimboli sais 一样

Ext.define('abc.xyz.MyWindow', {
extend : "abc.xyz.BaseWindow",
initComponent: function () {
var me = this;
me.callParent(arguments);

me.on('afterrender', function(el, eOpts){
console.log('second after render');
});
}
});

关于Extjs:覆盖特定监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24671165/

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