gpt4 book ai didi

javascript - extjs 按钮作用域

转载 作者:行者123 更新时间:2023-11-29 17:26:14 25 4
gpt4 key购买 nike

我试图了解以下场景中的范围。调用 searchTerms 时,scope:this 下的 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;
}

最佳答案

我想你是想这样做:

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;
}

关于javascript - extjs 按钮作用域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8588968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com