PDA

View Full Version : The Model Package for ExtJS and Sencha Touch



Dumas
17 Mar 2012, 5:55 PM
How much the same/different are the data models from Sencha Touch2 and ExtJS 4?

As far as I saw there is only the config property different?

Is there maybe a trick to see if the Ext object is Sencha Touch or ExtJS?

I would like to do something like:


var config = Ext.madeUpFunction.isTouch() ? {config:config} : config;
Ext.define('MyApp.data.SomeModel', config);


thanks
Roland

mitchellsimoens
19 Mar 2012, 5:40 AM
For the Model class that is pretty much it for when you create your model class.

Dumas
19 Mar 2012, 9:46 AM
Great :)

Will !!Ext.versions.touch be reliabe in the future to distinguish between Ext and Touch?

thanks

mitchellsimoens
19 Mar 2012, 9:56 AM
Between Ext JS 4 and Sencha Touch 2 is will be.

Dumas
19 Mar 2012, 10:06 AM
great, thx!

For other people interested in a solution:


/**
* Returns ExtJS4 or Sencha Touch 2 model config
*/
var plattformizeModelConfig = function(extJsModelConfig) {
if(Ext.versions.extjs) {
return extJsModelConfig; // nothing to change, we are on ext
} else if(Ext.versions.touch) {
// transform to Sencha Touch 2 data model
var config = {
extend: extJsModelConfig.extend,
config: extJsModelConfig
};
delete config.config.extend;
return config;
} else {
Ext.Error.raise('Could not recognize Library');
}
};

Ext.define('MyApp.model.MyModel',plattformizeModelConfig(config));

mitchellsimoens
19 Mar 2012, 10:10 AM
For a test I am wondering if you can use the config object and call this.initConfig(config); in the constructor if that will work.

Dumas
19 Mar 2012, 10:12 AM
Maybe I'm wrong, but this doesn't sound very bulletproof, since I can image that this behavior can easily change.