PDA

View Full Version : XTemplate - accessing nested json



asagala
3 May 2011, 4:39 PM
I am having trouble accessing nested json properties.

I have a DataView with a template defined like below.(simplified for the sake of this explanation)


this.dataview = new Ext.DataView({
store : this.store,
autoHeight:true,
tpl : new Ext.XTemplate(
'<tpl for=".">',
'<div class="t-item">',
'<p class="text">{text}</p>',
'<tpl if="id>10">',
<p class="text">{id}</p>',
'</tpl>',
'</div>',
'</tpl>'
),
loadingText:'Loading...',
overClass:'x-view-over',
itemSelector: 'div.tweet-item',
emptyText : 'No tweets to display'
});

The JSON loaded in the store looks something like this.



{
"results": [
{
"id": 1,
"text": "blahablah",
"user": {
"id": "1",
"name": "name1"
}
},
{
"id": 2,
"text": "blahablah2",
"user": {
"id": "12",
"name": "name2"
}
}
],
"success": true
}


What I am having issues with is accessing the id property in the template. I tried



'<tpl if="id>10">',
<p class="text">{id}</p>',
'</tpl>'




'<tpl for="user">',
'<tpl if="id>10">',
<p class="text">{id}</p>',
'</tpl>',
'</tpl>'


No success. I am sure this is a syntax issue but cant figure it out.

Thx

kendoctor
3 May 2011, 6:25 PM
you store has specified the fields id column?

asagala
3 May 2011, 8:30 PM
thx. You made me realized I had mapped the field I wanted to access under another name.