0

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,

player
  • 610
  • 6
  • 15
  • Only the model fields themselves go into fields, nothing else. For models you dont need to use config. Non-field properties (idProperty, etc) would just go under the class itself alongside fields. – OhmzTech Feb 21 '13 at 05:07
  • Ok, but isn't there an advantage in using config for model classes that we get getters and setters? – player Feb 21 '13 at 05:32

1 Answers1

1

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

CD..
  • 72,281
  • 25
  • 154
  • 163
  • Thanks CD. So what needs to go in config? According to sencha docs, config contains "List of configuration options with their default values, for which automatically accessor methods are generated". How are configuration options different from model fields? Thanks – player Feb 21 '13 at 22:47
  • A Model represents some object that your application manages. Models are registered via the model manager, and are used by stores, which are in turn used by many of the data-bound components in Ext and they all use the fields. I assume you'll use the config for passing additional parameters used in your logic, if needed, but not data. – CD.. Feb 21 '13 at 23:08