PDA

View Full Version : Access nested(belongsTo) JSON in Grid/column:templatecolumn/tpl:



zenrast
28 Jan 2014, 2:06 AM
Hello,

how can i access a nested JSON object inside "tpl:" of the Grid/column:templatecolumn/tpl?
The JSON comes from my "models" where i have "belongsTo" assocciation to a "Competitor" table.


belongsTo: [
{
associationKey: 'competitor',
model: 'MyApp2.model.Competitor',
getterName: 'getCompetitor'
},

Nested JSON code returned:


"result": [
{
"url": "www.mysite.com/",
"title": "Something text",
"date": {},
"id": 75,
"scans": {},
"competitor": {
"name": "Google",
"url": "www.google.com",
"dateadded": {},
"id": 690
}
},

I tried this without success:

columns: [
{
xtype: 'templatecolumn',
tpl: [
'<b>{title}</b></br>{url}</br>(XY)',
' <tpl for="getCompetitor">',
' Name {name}',
' </tpl>'
],
dataIndex: 'url',
text: 'MyTemplateColumn',
flex: 1
},

mitchellsimoens
6 Feb 2014, 11:45 AM
The data given to the column is only that of the record, not the associations. Instead, I'd use a regular column and use the renderer as you have access to the record then:


{
text : 'Foo',
renderer : function(value, meta, record) {
var competitor = record.getCompetitor(),
data = record.data,
tpl = new Ext.XTemplate('....');

data.competitor = competitor.data;

return tpl.apply(data);
}
}

zenrast
6 Feb 2014, 12:28 PM
Smart solution. Thanks mitchellsimoens :)