Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.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 extjs按钮范围_Javascript_Extjs_Extjs3 - Fatal编程技术网

Javascript extjs按钮范围

Javascript extjs按钮范围,javascript,extjs,extjs3,Javascript,Extjs,Extjs3,我试图理解以下场景中的范围。调用searchTerms时,范围下的此:此指的是searchTerms功能,而不是面板本身。这似乎与我从其他例子中观察到的不同。我能知道我犯了什么错误吗 function searchTerms(){ var searchGrid = new Ext.grid.GridPanel({ }); var searchPanel = new Ext.form.FormPanel({ region:

我试图理解以下场景中的范围。调用
searchTerms
时,
范围下的
:此
指的是
searchTerms
功能,而不是面板本身。这似乎与我从其他例子中观察到的不同。我能知道我犯了什么错误吗

function searchTerms(){
       var searchGrid = new Ext.grid.GridPanel({

        });

        var searchPanel = new Ext.form.FormPanel({
            region: 'south',
            height:150,
            items:[
            {
                xtype: 'textfield',
                fieldLabel: 'Keywords',
            },{
                xtype: 'textfield',
                fieldLabel: 'Label',
            },{
                xtype: 'datefield',
                fieldLabel: 'Valid till'
            },new Ext.Button({
                text: 'crawl',
                scope: this,
                handler: function(b,e){
                    Ext.Ajax.request({^M
                        url: '/discovery/tsearch',^M
                        params: {^M
                            keywords: this.items[0].getValue(),
                            label: this.items[1].getValue(),
                            valid: this.items[2].getValue(),
                        },
                    });
                }
            }),],
        });

        var regionPanel = new Ext.Panel({
            title: 'search',
            layout: 'border',
            items: [searchPanel, searchGrid]
        });

    return regionPanel;
}

我想你是有意这么做的:

function searchTerms(){
   var searchGrid = new Ext.grid.GridPanel({

    });

    var searchPanel = new Ext.form.FormPanel({
        region: 'south',
        height:150,
        items:[
        {
            xtype: 'textfield',
            fieldLabel: 'Keywords',
        },{
            xtype: 'textfield',
            fieldLabel: 'Label',
        },{
            xtype: 'datefield',
            fieldLabel: 'Valid till'
        }],
    });
    searchPanel.add(new Ext.Button({
            text: 'crawl',
            scope: searchPanel,
            handler: function(b,e){
                Ext.Ajax.request({
                    url: '/discovery/tsearch',
                    params: {
                        keywords: this.items[0].getValue(),
                        label: this.items[1].getValue(),
                        valid: this.items[2].getValue(),
                    },
                });
            }
        })
    );
    var regionPanel = new Ext.Panel({
        title: 'search',
        layout: 'border',
        items: [searchPanel, searchGrid]
    });

return regionPanel;
}

这是一个范围问题,当您创建按钮而不是searchPanel时,“这”将是searchTerm对象,您必须考虑代码首次执行时的分数,而不是事件发生时的分数。区别在于按钮添加到searchPanel,范围设置为searchPanel。为了能够将范围设置为searchPanel,必须首先定义searchPanel,这在您在searchPanel内部内联创建按钮时是不可能的。这有意义吗?@Chau:是的,很有意义,这就是为什么我必须使用
add
,如果你想内联使用的话,我认为您应该通过使用parentContainer或使用一些id和getCmp@RageZ:评论不是为你准备的:)我从来没有想过使用像
getCmp
这样的引用函数,但它实际上可能会工作。嗯@RageZ我有点困惑,部分原因是因为这篇文章。让我澄清一下,链接示例的“this”仅在调用对象的函数时确定,因此对象本身也是如此。而在我的例子中,“this”是在对象创建期间确定的,因此它指的是searchTerm对象。。。。