PDA

View Full Version : i can't get the combobox selected value after this combo has been loaded



alessio77
11 Apr 2012, 2:46 AM
Ext.get('ddlCustomer').getValue() does't work in this context, why?
what i'm wrong?




Ext.define('App.controller.ArchiveManager', {
extend: 'Ext.app.Controller',

stores: ['Customer', 'CustomerDocumentType', 'UserColumnsArchive', 'DbFieldType', 'LookUpTable'],
models: ['Customer', 'CustomerDocumentType', 'ColumnArchive', 'UserColumnsArchive', 'DbFieldType', 'LookUpTable'],
views: ['manager.ArchiveManager'],


init: function () {

this.getCustomerStore().load(); //load the combo that i'm interested in

...
.....code
........code
............code
.....................



//register an event for a store where i'll use the combovalue to filter the query
this.getLookUpTableStore().addListener('beforeload', this.LookUpTableStore_beforeload, this)

},



//this event will fire after the combo was loaded and by an user action
LookUpTableStore_beforeload: function (store, operation, eOpts) {

var customerID = Ext.get('ddlCustomer').getValue(); //<---here the value is undefined even if in this moment the combo is correctly loaded
operation.params = { id: customerId };
}
});


the combobox id is: ddlCustomer
the combobox xtype is: combo
are there other different ways to get a reference to the combobox value inside the controller?
for example getting reference to the linked combo store instead of the combo
what is the "better" way to follow?
anyway why the value is undefined??

friend
11 Apr 2012, 4:13 AM
It looks like you need to register the beforeload event prior to actually loading the combo.

alessio77
11 Apr 2012, 4:22 AM
using

Ext.getCmp('ddlCustomer').getValue();

instead of

Ext.get('ddlCustomer').getValue();

it works! why?

what's the difference?

friend
11 Apr 2012, 8:09 AM
Ext.getCmp() (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext-method-getCmp) returns a reference to a specified component. Ext.get() (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext-method-get) only returns an Ext.Element.