Search code examples
javascriptextjsviewmodelaliasstore

How can I reference a Model from a Store in ExtJS using alias?


I have a model:

Ext.define('MyAPP.model.myMod', {
   extend  : 'Ext.data.Model',
   alias   : 'model.myMod',
});

And a store:

   Ext.define('MyAPP.store.MyStore', {
      extend : 'Ext.data.Store',
      model  : 'MyAPP.model.myMod',
});

How can I reference the model on the store using the alias? I'm looking to be able to reference using only model: 'model.myMod', or model: 'myMod'.

I can't get this to work, I have always to reference it using full path: MyAPP.model.myMod.


Solution

  • You cannot reference a Model from a Store by using alias. BUT, you can use the property alternateClassName for your Model, like this:

    Ext.define('MyAPP.model.myMod', {
       extend  : 'Ext.data.Model',
       alternateClassName : 'myMod',
    });
    
    Ext.define('MyAPP.store.MyStore', {
          extend : 'Ext.data.Store',
          model  : 'myMod',
    });
    

    Now, you're able to reference using only model: 'myMod' from your Store. No need to reference it using full path: MyAPP.model.myMod.