View Full Version : Specify the entire class in property "model" of Ext.data.Store?

16 Oct 2014, 2:39 AM

I am a newbie in ExtJS4. I am coding the example from the page "http://docs.sencha.com/extjs/4.1.3/#!/guide/application_architecture". What I dont understand is when defining the store and gridPanel like this:

Ext.define (http://docs.sencha.com/extjs/4.1.3/#!/api/Ext-method-define)('AM.store.Users',{
extend:'Ext.data.Store (http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.data.Store)',
data:[{name:'Ed', email:'[email protected]'},{name:'Tommy', email:'[email protected]'}]

Ext.define (http://docs.sencha.com/extjs/4.1.3/#!/api/Ext-method-define)('AM.view.user.List',{
extend:'Ext.grid.Panel (http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.grid.Panel)',
title:'All Users',// we no longer define the Users store in the `initComponent` method
this.columns =[...});

1. Why when you define the model property of store, you have to writte the entire class and not just 'User' because when you define the grid, the property store is 'Users' and not the entire class. I have tried to specify just 'User' but tries to get localhost:8080/nameApplication/User.js


16 Oct 2014, 11:46 AM
Interesting question, makes me dizzying as well a lot of times. But the tutorial you referenced, says the following:

By including the stores that our Users controller cares about in its definition they are automatically loaded onto the page and given a storeId, which makes them really easy to reference in our views (by simply configuring store: 'Users' in this case).

If you define a store in a controller stores section it is assigned a storeId automatically by which an instance of the store will be looked up in the StoreManager if you refer to it in a view. The controller however lacks this functionality for the model. There is no such lookup for model instances in the ModelManager as far I am aware of. For example you can not assign a modelId to a Model by which it can be looked up easily in some class. I think nobody needs such functionality - such things you do in stores where you search for records/models.

So, the difference is that the StoreManager returns an instance of a store and the Store class needs a constructor / class of the model for making records in the store. I think that is the explanation. One is an instance the other a class.

And on the other hand in the Controller it seems to be possible to load the class with its single name:

Ext.define('AM.controller.Users', {
extend: 'Ext.app.Controller',
stores: ['Users'],
models: ['User'],

There the model-classes are required/loaded from the App.model namespace...That is a bit confusing...

17 Oct 2014, 1:37 AM

I still find it a little confusing because in some examples I have seen that in the model of a datastore they dont specify the entire class so I still dont get it


17 Oct 2014, 1:45 AM
Probably in the case these models do not have a defined namespace ...