PDA

View Full Version : Ext JS 4.2 - Passing config to function



kayasa
5 May 2015, 12:02 AM
I need to use the store in a function but unable to do so, as store is created in the Constructor and not visible in the function.

Currently, my constructor looks like


constructor: function(config) { console.log('1) Constructor called');
this.addEvents("selectionchange");
config = config || {};
this.runtime = Ext.isDefined(xp.navigationManager);
console.log('this.runtime -- '+this.runtime);
if(this.runtime) {
var ds = config.datasourceInstance || config.store;
if (ds) {
config.store = Ext.data.StoreManager.lookup(ds);
config.store.on('load', function() {
console.log('Loaded ****************');
});
}
}
this.callParent([config]);
console.log("constructor FINISH");

},

Then the onLoad function has the code


onLoad : function() { console.log('On Load');

/* var links = [
{source: "Start", target: "Dept Approver", type: "approve"},
{source: "Dept Approver", target: "Amount>20", type: "approve"},
{source: "Amount>20", target: "Div Approver", type: "approve"},
{source: "Amount>20", target: "Section Approver", type: "approve"},
{source: "Amount>20", target: "Dept Approver", type: "reject"},
{source: "Div Approver", target: "End", type: "approve"},
{source: "Section Approver", target: "End", type: "approve"}
];*/

var links = [];
var count = config.store.getCount();

for (var i = 0; i < count; i++) {
var rec = store.getAt(i);
console.log('rec ****'+rec.get('out_source_mv'));
links.push({source: rec.get('source_mv1'), target: rec.get('source_mv2'), type: rec.get('source_mv3')});
}



var nodes = {};

.

The problem here is that onLoad is not able to find the config as it was created inside constructor. This is the error that I get in browser console

52329

I tried doing

config.store.on('load', function(config) {

onLoad : function(config) {

In this case I get the error

52330

Can someone please help me with the correct way of using store within the onLoad method.

Thank you

f.baron
5 May 2015, 12:51 AM
Hi!

As the onLoad handler receives the 'load' event params you can get the store as following



onLoad: function(store) {
var count = store.getCount();
...
}