PDA

View Full Version : Uncaught TypeError: Cannot call method 'on' of undefined



KrasimirTsonev
12 Jul 2012, 6:01 AM
Hello,

I'm using Ext Designer 1.2.2 with Ext JS 3 (http://docs.sencha.com/ext-js/3-4/). I successfully export the project, but when I try to run it I receive:

Uncaught TypeError: Cannot call method 'on' of undefined
I dig a little into the generated code and here is what I found:
The problem is in the following code:

store = Ext.StoreMgr.lookup(store);
store.on({
scope: this,
beforeload: this.beforeLoad,
load: this.onLoad,
exception: this.onLoadError
});

I.e. here "store" returned by the StoreMgr is not defined and of course we can't access its method "on". It is not defined because it is missing in StoreMgr. So, I started to search where we add things inside the StoreMgr and found that this is happening in the constructor of Ext.data.Store by using

Ext.StoreMgr.register(this);
So far so good ... it is clear for me that once the "store" is created register itself in that store manager. I simply put a console.log in the very first line of the constructor of the store and that log never occur. It looks like there is no any initial store creation. In other words I need a "store" object before it is created.
In my case I have a PagingToolbar with a store set and when that component needs it the store is still not created.

So, my questions is: can you give me any advice how to fix the problem or just any direction of the Stores' things. I.e. how are they created, initialized etc ...

KrasimirTsonev
12 Jul 2012, 7:00 AM
However I changed this line of code:

return Ext.isObject(id) ? (id.events ? id : Ext.create(id, 'store')) : this.get(id);
to

if(Ext.isObject(id)) {
return (id.events ? id : Ext.create(id, 'store'));
} else {
var store = null;
if(store = this.get(id)) {
return store;
} else {
return Ext.create(id, 'store');
}
}


This little fix created the stores, but they were empty. I.e. the information which I entered by using the designer was missing. And at the end I notice that the stores are actually created in xds_index.js and because we have a custom index.js that logic wasn't trasnfered. Once I copied the lines the app runs successfully.

Hope that this helps to someone :)