vendredi 28 mars 2014

Howto Override / Change the constructor signature in SA

Hi guys,



how can I modify the constructor of a class in SA?



If I add a class to a model the constructor is parameterless and I cannot change it. If I add a custom class and add a constructor field, I get an exception. I have resorted to overriding the class (Generate Override) and modified the constuctor here.



That is what my class looks like:



Ext.define('MyApp.model.Client', {

extend: 'Ext.data.Model',

alias: 'model.client',



requires: [

'MyApp.model.override.Client',

'Ext.data.Field'

],



fields: [

{

name: 'firstName'

},

{

name: 'lastName'

}

],



constructor: function() {

var me = this;

me.processClient(me);

me.callParent(arguments);

},



processClient: function(config) {

console.log('client created');

}

});



And my overridden class is defined as:



Ext.define('MyApp.model.override.Client', {

override: 'MyApp.model.Client',

constructor: function(args) {

Ext.apply(this, args);

}

});



So this allows me to do:

var myClient = Ext.create('MyApp.model.Client', {

lastName: 'Mayer',

firstName: 'Ute'

});



Is that the way to go?



Thanks




Aucun commentaire:

Enregistrer un commentaire