PDA

View Full Version : How to instantiate Model objects



gmn314
5 Jun 2012, 9:19 AM
Hi,

I see in examples, a Model object is instantiated as follows:

Ext.define('occupationModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'code', type: 'int'},
{name: 'occup', type: 'string'}
]
}

If I try to instantiate it, as I do other objects:

var occupationModel = new Ext.data.Model({
fields: [
{name: 'code', type: 'int'},
{name: 'occup', type: 'string'}
]
}

I get a runtime exception: me.fields is undefined

I would like to understand what is happening here. Why does the second method not work?

Thanks!

mitchellsimoens
7 Jun 2012, 1:58 PM
If you have


Ext.define('occupationModel', {
extend: 'Ext.data.Model',

fields: [
{name: 'code', type: 'int'},
{name: 'occup', type: 'string'}
]
});

Then you can create an instance via:


Ext.create('occupationModel', {
code : 1,
occup : 'foo'
});

or


new occupationModel({
code : 1,
occup : 'foo'
});