PDA

View Full Version : How to extend an extension of Ext.data.Model



Stokes
14 Feb 2012, 9:06 AM
If I have a Model extension with certain fields, how can I extend that model and add a few specialized fields?

This seems like a pretty standard OO thing to do, but I can't find any examples that explain it. Something like this:

Ext.define('Fruit', {
extend: 'Ext.data.Model',
fields: [
{name:'ripe', type:'boolean'},
{name:'color', type:'string'}
]
});
Ext.define('Apple', {
extend: 'Fruit',
fields: [ // <-- this overwrites the parent's fields, which is not desired.
{name:'appleBreed', type:'string'}
]
});
// we'd like to be able to create a concrete class with fields from the child and parent.
var appleInstance = Ext.create('Apple', {
color: 'red',
appleBreed: 'Johnathan',
ripe: true
});

Any ideas?

Stokes.

mitchellsimoens
14 Feb 2012, 9:36 AM
It's not going to merge the two, it's going to overwrite. Extending an already extended model isn't going to work too easily at all. I would suggest just extending Ext.data.Model and add in all your fields in each.

Stokes
14 Feb 2012, 10:58 AM
Then this seems like a reasonable feature request, since we're defining a "class" that is a type of model.

If the Model class had something like initComponent(), where fields could be added, then extensions could modify the parent's config before 'construction'.

Otherwise, it should probably be documented somewhere that this is discouraged (or problematic).

Thanks for the reply,
Stokes.