3

I am upgrading my extjs 4.2 app to extjs 5.1 .

In ExtJs 4.2, I have code for creating dynamic module, but

in ExtJs 5.1 Ext.ModelManager.getModel has been deprecated and as per ExtJs 5.1 docs it saying use Ext.data.schema.Schema instead.

I try using Ext.data.schema.Schema.lookupEntity("DynamicModel"), but it throws error saying

[E] Ext.data.schema.Schema.lookupEntity(): No such Entity "DynamicModel".

How can I get any model object in ExtJs 5 ?

How can I achieve replacement for getModel() method in extjs 5.1 , Please find my code bellow,

if (!Ext.ModelManager.getModel('DynamicModel')){
    Ext.define('DynamicModel', {
       extend: 'Ext.data.Model',
       idProperty : uniqueIdProperty,
       fields: fields
    });
} else {
    Ext.ModelManager.getModel('DynamicModel').setFields(fields);
}

2 Answers 2

3

If you want to check that your model has already been created then you can use isCreated of Ext.ClassManager

Ext.ClassManager.isCreated('MyModel');

If it returns true then you can do

Ext.ClassManager.get('MyModel')

Using Schema: Fiddle

if(!Ext.data.schema.Schema.instances.default.hasEntity('MyModel')){ // a default schema instance is created by default
            Ext.define('MyApp.models.MyModel', {
               extend: 'MyApp.models.Base',
               fields: [{name: 'field'}]  
            });
        } else {
            Ext.data.schema.Schema.instances.default.getEntity('MyModel');// returns the constructor MyApp.models.MyModel()
        }
0

If you run into issues with the above syntax, as I did, because 'default' is a reserved word, you can use the following syntax:

if (!Ext.data.schema.Schema.instances['default'].getEntity('MyModel')) {
    ...
}

IDK why Sencha is using reserved words for properties, but...oh well...

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.