当前位置: 代码迷 >> JavaScript >> Extjs createDelegate 步骤使用
  详细解决方案

Extjs createDelegate 步骤使用

热度:283   发布时间:2012-11-10 10:48:50.0
Extjs createDelegate 方法使用
关于Extjs 的 createDelegate我也接触不久。
我们自己写一个组件,使用继承时。我们会在继承中写:
Ext.MyCmp = function(config){
    Ext.apply(this,config);
    this.message = 'show message method run';
    this.buttons = [
       {
           xtype:'button',
           text:'click',
           handler:this.showMessage.createDelegate(this)
       }
    ];
    Ext.MyCmp.superclass.constructor.call(this);
}
Ext.extend(Ext.MyCmp,Ext.Window,{
   showMessage : function(){
      Ext.Msg.alert('提示',this.message);
   }
});

当然,如果在按钮的事件那里写this.showMessage是不行的。
这个方法跟call方法相当,是把这个方法放到this这个作用域运行。
  相关解决方案