Loading hasMany data in ExtJS

I am trying to load "nested" data into a hasMany relation in ExtJS4. My model looks like this:

 Ext.define("Entrypage.model.Entrypage",{ extend: "Ext.data.Model", fields: ['id','title','urlkey','text','picture','keywords', 'searchterms','description','critriamodus'], hasMany: {model: 'EntrypageCriterium',name:'brands'}, proxy: { type: 'ajax', url: '/Admin/extjson/entrypages', reader: {type:'json', root:'entrypages'} } }); 

And EntrypageCriterium :

 Ext.define("Entrypage.model.EntrypageCriterium",{ extend: "Ext.data.Model", fields: ['id','type','title'] }); 

I load my data like this:

 Entrypage.load("nikon-coolpix",{success:function(record,options,success){ console.log(record); }}); 

It loads perfectly. Json returns this:

 { "success": true, "entrypages":[{ "id":"1", "urlkey":"nikon-coolpix", "title":"Nikon Coolpix", "text":"Some blahblah about Nikon", "keywords":"nikon,coolpix,digitale,camera", "description":"Nikon Coolpix camera's", "picture":"Nikon Coolpix camera's", "searchterms":"nikon coolpix", "language":"nl", "brands":[ {"id":27038,"title":"Nikon","type":"brand"} ] }] } 

But when I try record.brands() or something like that. It says that such a method does not exist. I think something is going wrong when matching data in the model.

Any help would be greatly appreciated!

+8
json javascript extjs extjs4
source share
2 answers

Finally found a problem. For any future reference:

If you use packages in the new MVC ExtJS framework, define the full path to the related class in your association as follows:

 hasMany: {model: 'Entrypage.model.EntrypageCriterium', name: 'brands', associationKey:'brands'} 
+17
source share

You need to set the associationKey property in the hasMany association so that it knows which json property to use.

 hasMany: {model: 'EntrypageCriterium',name:'brands', associationKey:'brands'} 

see the section "Loading nested data" here:

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.reader.Reader

+3
source share

All Articles