sách gpt4 ai đã đi

javascript - extjs 按钮作用域

In lại 作者:行者123 更新时间:2023-11-29 17:26:14 25 4
mua khóa gpt4 Nike

我试图了解以下场景中的范围。调用 searchTerms giờ,scope:this 下的 cái này 指的是 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;
}

1 Câu trả lời

我想你是想这样做:

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
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com