Reputation: 610
I am fairly new to extjs. I am declaring a model class "product". I am just not sure where the properties of this class go to? fields or config. With Sencha 4.1 adding fields to config would give me getters and setters but is it the correct approach? Which of the following two is the preferred way of defining model?
Ext.define('MyApp.model.product', {
extend: 'Ext.data.Model',,
config: {
color: '',
price: 0,
}
});
OR
Ext.define('MyApp.model.product', {
extend: 'Ext.data.Model',,
fields: [
"color",
"price"
]
});
Thanks,
Upvotes: 0
Views: 881
Reputation: 74146
You configure your fields (and use get()
and set()
):
Models are defined as a set of fields and any arbitrary methods and properties relevant to the model. The fields array is turned into a MixedCollection automatically by the ModelManager, and all other functions and properties are copied to the new Model's prototype.
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Model
Upvotes: 1