我想重写 Ext.grid.column.Column 类的 initComponent( ) 方法。但它是如何执行所有这些行的。基本上我想从元素中删除监听器并将其分配给其他元素。
Ext.override(Ext.grid.column.Column,
{
initComponent: function(){
.
. //All lines are as it is till me.callParents();
.
.
.
.
.
.
.
// Initialize as a HeaderContainer
me.callParent(arguments);
me.on({ <<<------------------------------Do not need these.
element: 'el',
click: me.onElClick,
dblclick: me.onElDblClick,
scope: me
});
me.on({ <<<------------------------------Do not need these.
element: 'titleEl',
mouseenter: me.onTitleMouseOver,
mouseleave: me.onTitleMouseOut,
scope: me
});
}
}
我不想将监听器附加到“el”和“titleEl”,因此我删除了这些行。但它仍然如何增加听众。 我还在 AfterRender 函数中编写了 me.un() 。即使它为“El”和“titleEl”添加了监听器
有人可以指导我哪里错了吗???
最佳答案
而不是使用 Ext.override
,使用Ext.define
创建一个子类。当您重新定义initComponent
时方法,您可以使用this.superclass.superclass.initComponent.call
跳过Ext.grid.column.Column#initComponent
.
Ext.define('MyApp.grid.column.Column', {
extend: 'Ext.grid.column.Column',
alias: 'widget.mycolumn',
initComponent: function(){
// Pre-initComponent from column class here
// Ext.grid.header.Container#initComponent
this.superclass.superclass.initComponent.call(this);
// Do optional stuff here
}
});
然后,当您创建新列时,请使用 xtype: 'mycolumn'
使用您自己的实现,同时仍然能够根据需要使用常规列。
关于extjs4 - 重写 initComponent() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16211380/