【问题标题】:override initComponent() method覆盖 initComponent() 方法
【发布时间】:2013-04-25 09:40:35
【问题描述】:

我想重写 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”添加了监听器

谁能指导我哪里错了?????

【问题讨论】:

    标签: extjs4 extjs-mvc


    【解决方案1】:

    不要使用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' 来使用您自己的实现,同时仍然可以根据需要使用常规列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      • 2016-03-06
      • 2018-03-27
      • 2014-05-27
      • 2014-01-04
      • 2021-11-11
      • 2010-11-16
      相关资源
      最近更新 更多