PDA

View Full Version : Solved - but with a question: TreePanel Store me.store is undefined using MVC



murrah
25 Jul 2012, 5:32 PM
Hi,

I just wanted to post this in case someone else had the same problem. I am on the learning curve with ExtJS 4 and am setting up a test MVC app to learn.

My first attempt to connect a Store to a TreePanel resulted in the following error in Ext.tree.Panel:
me.store is undefined Line 191

What I had was my store:
Ext.define('AM.store.Tree', {
extend: 'Ext.data.TreeStore',
model: 'AM.model.Tree',
autoLoad: true,
alias : 'widget.usertreestore'
...

which I added to the tree like so:
store : 'usertreestore'

Using the debugger I found that the
me.store = Ext.StoreMgr.lookup(me.store); in Ext.tree.Panel.initComponent()
--> Ext.data.StoreManager.lookup()
--> Ext.uti.AbstractMixedCollection.get()
--> mk = me.map[key] where the key was, of course 'usertreestore'.

However, the map[] was expecting 'Tree'

So, changing the TreePanel config to
store :'Tree' solved the problem.

Now, my question is, it seems that in some places the xtype / alias can be used and in others (eg tree stores) it cant. Am I missing something, or is that intentional or is there a bug here?

Thanks,
Murray

debabrata
25 Jul 2012, 9:28 PM
I think alias/xtype is used for component and store is not a component.

scottmartin
26 Jul 2012, 10:17 AM
The use of storeId: 'myStore' will help you out.

Scott.

murrah
26 Jul 2012, 1:50 PM
Aha... explains why.

Thanks!

murrah
28 Jul 2012, 11:11 PM
The use of storeId: 'myStore' will help you out.

Scott.

Thanks Scott. I have just got back to test your suggestion and it doesn't seem to work for me.

On my tree store I added:
storeId : 'myTreeStore' and on the Tree Panel I used
store : 'myTreeStore' which I think is what you were suggesting. This resulted in
TypeError: me.store is undefined As mentioned in my original post, if I use
store :'Tree' it works.

The docs for Ext.data.AbstractStore say:
storeId : String

Unique identifier for this store. If present, this Store will be registered with the Ext.data.StoreManager, making it easy to reuse elsewhere.

Note that when store is instantiated by Controller, the storeId will be overridden by the name of the store.
Re: the last line - since I am instantiating on the controller, I guess that is why it doesn't work. I would rather use the controller method to instantiate since this is an MVC type test app so I will stick with using the store's defined name ('Tree').

Perhaps there is something else I am misunderstanding here? Anyway...

Thanks again for your help Scott. I really want to get across ExtJS 4 and your responses are invaluable in explaining these "little" things that make all the difference.

Murray

scottmartin
29 Jul 2012, 7:43 AM
Depends on your use:

If you are using storeId, then it places it in the store manager and you can access it using:



store: Ext.data.StoreManager.lookup('myTreeStore') // storeId


If you want to use it in your controller using the naming convention:


var store = getTreeStore();


alias: widget.usertreestore is simply creating an xtype .. and xtype is for components, which a store is not.

Scott.

murrah
29 Jul 2012, 1:20 PM
Great, thanks, that is now clear!

Go well,
Murray