goh*_*goh 2 javascript extjs extjs3
我试图了解以下场景中的范围.拨打电话时searchTerms
,this
下scope:this
指的是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;
}
Run Code Online (Sandbox Code Playgroud)
我想你打算这样做:
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;
}
Run Code Online (Sandbox Code Playgroud)