I've a combobox inside panel items and placed a select event in combobox listeners. Event's function calls a global method but this global function executes during page load.
I'm using this combobox selection method on several classes. Therefore a global function will be to easy. So need to use with normal behaviour during combobox's items selection. How can I achieve to this adjustment?
Global function:
Ext.define('MyApp.BaseMethods', {
requires: [],
singleton: true,
// Instead of using method content several times; passing comboname and required JSON value on arguments
comboQuery: function(comboname, JSONValue) {
var query = Ext.ComponentQuery.query(comboname)[0].getSelectedRecord();
var requiredValue = query.get(JSONValue);
return requiredValue;
},
});
and Panel:
Ext.define('MyApp.view.FooPanel', {
extend: 'Ext.panel.Panel',
items: [{
xtype: 'foocombo',
listeners: {
// Trying to pass required information through parameters
select: MyApp.BaseMethods.comboQuery('[name=myfoocombo]', 'foojsonvalue'),
scope: me
}
}]
});
When runing this approach; Global function runs during page-load on button click which displays FooPanel and it's items and give error because of did not able to select combo item.;
Uncaught TypeError: Cannot read property 'getSelectedRecord' of undefined
No need to delay just need to change the way.
As your providing a function to
selectand it will call on page load or component create so instead of this you need to call inside ofselectevent function.So for this as you mentioned I'm using this combobox selection method on several classes for this you can create a common component and you can get value easily on that common component
selectevent.Example
In this FIDDLE, I have created a demo. Hope this will help/guide you to achieve your requirement.
CODE SNIPPET