Javascript Ext js重写初始化组件函数
我试图重写Ext.window.MessageBox类的initComponent函数中的一些代码。但我改变的东西都没有得到应用 这里有什么问题?我错过什么了吗Javascript Ext js重写初始化组件函数,javascript,html,extjs,overriding,Javascript,Html,Extjs,Overriding,我试图重写Ext.window.MessageBox类的initComponent函数中的一些代码。但我改变的东西都没有得到应用 这里有什么问题?我错过什么了吗 Ext.define('hds.override.MessageBox', { override: 'Ext.window.MessageBox', initComponent: function() { console.log("init component 1"); //not reached t
Ext.define('hds.override.MessageBox', {
override: 'Ext.window.MessageBox',
initComponent: function() {
console.log("init component 1"); //not reached
this.callParent();
console.log("init component 2"); //not reached
}
});
编辑:
我还尝试用extend替换override,但仍然没有到达内部组件。更改为extend时是否需要更改文件的位置???如果要更改Ext.Msg的行为,它是类Ext.window.MessageBox的实例,则需要将其作为重写类的实例:
Ext.define('MyMessageBox', {
override: 'Ext.window.MessageBox',
initComponent: function() {
this.callParent();
//your changes here..
}
},function() {
Ext.MessageBox = Ext.Msg = new this();
});
查看这里,我在initComponent中更改了默认填充,如果要更改Ext.Msg的行为,它是类Ext.window.MessageBox的实例,则需要将其作为重写类的实例:
Ext.define('MyMessageBox', {
override: 'Ext.window.MessageBox',
initComponent: function() {
this.callParent();
//your changes here..
}
},function() {
Ext.MessageBox = Ext.Msg = new this();
});
查看这里,我在initComponent中更改了默认填充是否在函数中调用this.callParent?您确定需要覆盖Ext.MessageBox而不是Ext.window.MessageBox吗?我已尝试使用callParent,但没有帮助。您是否尝试覆盖Ext.window.MessageBox?是的,没有更改。但是我更新了我的代码,因为我认为这是另一个错误。我测试了一些东西,导致Ext.MessageBox是一个单例,它在到达代码之前被实例化,所以需要扩展它。你在函数中调用this.callParent吗?您确定需要覆盖Ext.MessageBox而不是Ext.window.MessageBox吗?我已尝试使用callParent,但没有帮助。您是否尝试覆盖Ext.window.MessageBox?是的,没有更改。但是我更新了我的代码,因为我认为这是另一个错误。我测试了一些东西,因为Ext.MessageBox是一个单例,它在到达代码之前被实例化,所以您需要完美地扩展它!非常感谢!完美的非常感谢!