extjs按钮作用域 [英] extjs button scope
本文介绍了extjs按钮作用域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在以下情况下了解范围.调用searchTerms
时,scope:this
下的this
是指searchTerms
函数,而不是面板本身.这似乎与我从其他示例中观察到的有所不同.我可以知道我犯了什么错误吗?
I am trying to understand scope in the below scenario. When calling searchTerms
, this
under the scope:this
refers to the searchTerms
function rather than the panel itself. It seems to be different from what I observe from other examples. May I know what mistakes did i make?
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;
}
这篇关于extjs按钮作用域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文