PDA

View Full Version : XTemplate syntax



miroperez
31 Jan 2011, 4:28 PM
from the examples in:

http://dev.sencha.com/deploy/touch/docs/?class=Ext.XTemplate

Is there a way to get directly to the kids[0].name property in the tpl?

I tried:



var tpl = new Ext.XTemplate(
'<p>KID 0: {kids[0].name}</p>','
);


But that didn't seem to work. Or is there a way to write a function which can do the logic to return a default if there are 0 items?

mitchellsimoens
31 Jan 2011, 6:48 PM
You are only trying to get the first kid in a record?

weenradio
31 Jan 2011, 11:17 PM
Try this:


var tpl = new Ext.XTemplate(
'<p>KID 0: {[values.kids[0].name]}</p>','
);

weenradio
31 Jan 2011, 11:32 PM
Added check for no kids:



var tpl = new Ext.XTemplate(
'<tpl if="this.hasKids(values.kids)">',
'<p>Kid 0: {[values.kids[0].name]}</p>',
'</tpl>',
{ hasKids : function (val) {
return ((val) && (val.length > 0));

}}
);