View Full Version : Nested objects in a model?

20 Dec 2011, 2:34 AM
I receive the below from an api call. Is it possible to use nested objects in a model? If so, how would I use the regModel to register the below hierarchy?


"Store": {
"name":"The Widget Store",
"address_1":"91 Widget Rd",
"Suburb": {
"name":"Widget Land"

Ext.regModel('Store', {
fields: ['id', 'name', 'address_1', 'address_2', 'marker', 'lat', 'lng', 'suburb']

20 Dec 2011, 5:17 AM
You won't be able to easily. You have to go to the reader, use the createAccessor method like it does for the total property in order to get that.

reader.getSuburb = reader.createAccessor('Suburb');

Now the reader will have a getSuburb method that you can execute passing the raw data.

20 Dec 2011, 5:40 PM
You could jump through some hoops with mappings. It's a bit unpleasant though.

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

fields: [
{name: 'id', mapping: 'Store.id'},
{name: 'name', mapping: 'Store.name'},
{name: 'suburb', mapping: 'Suburb.name'}

Ext.regModel is deprecated, use Ext.define. Note also that models are just classes and live in the global namespace, so you should really namespace them just like you would any other class.