【问题标题】:ExtJS button handlingExtJS 按钮处理
【发布时间】:2011-11-02 02:51:47
【问题描述】:

向按钮添加功能的最佳方式是什么? (具体范围)

脏例子:

form.Login= function(config){
if ( typeof config !== 'object' ) { config = {}; }



    var tbarBottom = {
    xtype: 'toolbar',
    dock: 'bottom',
    items: [{
        xtype:'spacer'
    },{
        text: 'Reset',
        handler:function(button,event){
            console.log(this); // ehh... how do I this.reset() from here? 
                              //( "this" is the buttons scope, not the forms scope )

        }]
    }
    config.dockedItems= [tbarBottom];
    form.Login.superclass.constructor.call(this,config);

Ext.extend( form.Login, Ext.form.FormPanel,{

reset: function() {
    this.reset()// I want to call this function
}

});

我在 ExtJs 4 中看到了使用

的示例
this.up('form').reset();

我也可以

this.ownerCt.ownerCt.reset()

但不知何故,这两个人都觉得很尴尬。 (.up 少得多,虽然因为我玩的是触摸,我不认为“up”是一个选项)

【问题讨论】:

    标签: function extjs scope sencha-touch extend


    【解决方案1】:

    使用这个

    {
        text: 'Reset',
        handler:function(button,event){
        console.log(this); // ehh... how do I this.reset() from here? 
                                  //( "this" is the buttons scope, not the forms scope )
        },
       scope : this
    } 
    

    【讨论】:

    • 出于好奇,这是所有javascript都可以做到的事情,还是ext实现的?
    • 范围可以传递给任何函数,例如yourFuction.call(yourScope, function-Arguments)。像我在上面的代码中那样定义作用域是 Ext Js 传递作用域对象的方式
    猜你喜欢
    • 1970-01-01
    • 2017-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-20
    • 1970-01-01
    相关资源
    最近更新 更多