0
this.stateComboBox
を使ってコンボボックスを参照すると失敗します。ただし、同じ構文を使用すると、テキストフィールドで正常に動作します。this.objectNameの代わりにExt.getCmp( 'id')を使用しなければならないのはなぜですか?
コンボボックスに 'id'を指定すると、Ext.getCmp('stateComboBox')
を使用して参照できます。しかし、私はそれが悪い練習であることを知っています。
私が間違っていることを教えてもらえますか?最後の注記を参照してください。
おかげ
Ext.define('App.view.prospects.Show', {
alias: 'widget.prospectsshow',
extend: 'Ext.form.Panel',
iconCls: 'icon-prospects',
itemId: 'prospectsshow',
constructor: function(config) {
var cfg = config || {};
this.phoneNumberTextField = Ext.create('Ext.form.field.Text', {
anchor: '100%',
allowBlank: true,
fieldLabel: 'Phone Number',
labelAlign: 'top',
margin: '5 5 5 0',
tabIndex: 1
});
this.stateComboBox = Ext.create('Ext.form.field.ComboBox', {
anchor: '100%',
displayField: 'name',
editable: false,
fieldLabel: 'State',
forceSelection: true,
id: 'stateComboBox', // I hate using this. See note below.
labelAlign: 'top',
margin: '5 5 5 5',
mode: 'local',
store: this.stateStore,
tabIndex: 22,
triggerAction: 'all',
valueField: 'id',
valueNotFoundText: ''
});
// Lots of objects removed for clarity....
Ext.applyIf(cfg, {
border: false,
items: Ext.create('Ext.form.Panel', {
bodyStyle: 'background-color: #F1F1F1;',
items: this.prospectPanel // Not shown above, but contains this.phoneNumberTextField and this.stateComboBox
}),
frame: false,
layout: 'fit'
});
this.superclass.constructor.call(this, cfg);
},
setData: function(record) {
// This works fine.
this.phoneNumberTextField.setValue(record.phone_number);
// This fails. No error in console. Just does nothing. WHY?
//this.stateComboBox.setValue(record.state_id);
// This works. But, I hate using 'id'. It is BAD practice.
Ext.getCmp('stateComboBox').setValue(record.state_id);
}
});
私がそうすると、エラーメッセージが表示されます。 "Uncaught TypeError:未定義のメソッド 'setValue'を呼び出すことはできません。 もしそれがうまくいくならば、おそらくそれは私が間違っていることについての手掛かりを提供するでしょう。 明確にするために、 'id'パラメータを 'itemId'に変更しました。次に、 'setValue'行を次のように変更しました。 this.getComponent( 'stateComboBox')。setValue(record.state_id); 上記のエラーが返されました。 – Eric
また、this.getComponent( 'internalid');を使用するための提案。 this.phoneNumberTextField.setValue(record.phone_number);でテキストフィールドのオブジェクト参照が機能する理由を説明していません。コンボボックスでは失敗します。 – Eric
おかげで。後でもう一度試してみましょう。しかし、私はinitComponentを使用していました(これは私の標準的な習慣です)、私が読んだ別の投稿のためにConstructorを使用しました。 [この記事](http://stackoverflow.com/questions/6555136/extjs-4-what-is-the-properway-to-perform-inheritance)には5つの方法が示されています思う。本当の問題は、ExtJSが非常に多くのメソッドを許していることです。各メソッドの長所や短所を明確に理解することは不可能です。 – Eric