2
以下のシナリオの範囲を理解しようとしています。 searchTerms
を呼び出す場合、scope:this
の下のthis
は、パネル自体ではなくsearchTerms
関数を指します。私が他の例から見たものとは異なるようです。私は何のミスをしたのか分かりますか?extjsボタンスコープ
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;
}
は、私が知っているかもしれませんか? – goh
これはスコープの問題です。「this」は、searchPanelではなくボタンを作成するときにsearchTermオブジェクトになります。イベントが来るときにコードが最初に実行されるときにスコアを考える必要があります。 – RageZ
違いは、ボタンはsearchPanelに*追加*され、スコープはsearchPanelに設定されます。スコープをsearchPanelに設定できるようにするには、最初にsearchPanelを定義する必要があります。これはsearchPanel内に* inline *ボタンを作成すると不可能です。それは意味をなしますか? – Chau