Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript senchaextjs属性范围_Javascript_Extjs - Fatal编程技术网

Javascript senchaextjs属性范围

Javascript senchaextjs属性范围,javascript,extjs,Javascript,Extjs,目前我正在使用ExtJS3.4,我遇到了以下问题。我在constructur中创建了一个GridPanel,我设置了一个名为“bla”的变量名,值为“test2”,设置完这个属性后,我会提醒它确保设置正确。这管用!。然而,当我的gridpanel中的一个按钮被按下时,它就不能再读取bla属性,并说它“未定义” 我跳过了代码中与问题无关的部分;) 请参见下面的代码 Ext.define('SC.view.WorkOrderHourGrid' ,{ extend: 'Ext.gri

目前我正在使用ExtJS3.4,我遇到了以下问题。我在constructur中创建了一个GridPanel,我设置了一个名为“bla”的变量名,值为“test2”,设置完这个属性后,我会提醒它确保设置正确。这管用!。然而,当我的gridpanel中的一个按钮被按下时,它就不能再读取bla属性,并说它“未定义”

我跳过了代码中与问题无关的部分;)

请参见下面的代码

    Ext.define('SC.view.WorkOrderHourGrid' ,{

    extend: 'Ext.grid.GridPanel',

    bla:"test",
    tbar: null,

    store:null,
    plugins:null,

    //Methods


    constructor:function(p_Store,config){
        this.tbar = this.buildTbar();
        this.bla = " test2";
        this.store = p_Store;

        //alerting bla attribute outputs test 2 !!
        alert(this.bla);


        var rowEditor = new Ext.ux.grid.RowEditor({
            saveText: 'Update'
        });

        this.plugins = [rowEditor];


        SC.view.WorkOrderHourGrid.superclass.constructor.call(this,config);
    },
    buildTbar:function()
    {
        return [{
            text: 'Toevoegen',
            handler: function(){
                tryOut();
            },
            //the button i was talking about
            handler:this.onAdd


        }];
    },
    onAdd:function(btn, ev)
    {
        //this outputs undefined !!!
        alert(this.bla);
    }


});

onAdd功能中的作用域是按钮。这就是为什么 bla未定义

尝试更改buildTbar函数,如下所示:

buildTbar:function()
{
    return [{
        text: 'Toevoegen',
        scope: this,
        //the button i was talking about
        handler:this.onAdd


    }];
},

我没有测试过它!:)

我认为这个范围是指按钮,而不是网格,这就是为什么会发生这种情况。检查
this.reowner.bla
或尝试通过idworks搜索该组件。感谢works,我发现它执行扩展gridpanel类的方法很奇怪,因为它的范围不应小于2,对吗?可能有点混乱。“scope”参数告诉处理程序在哪个范围内执行,谁通常在组件的范围内运行;“this”(用于this.onAdd和scope)就是网格:)