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

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');
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 ****************');
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


I tried doing

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

onLoad : function(config) {

In this case I get the error


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

Thank you

5 May 2015, 12:51 AM

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

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