|
|||||||
![]() |
|
|
Thread Tools |
|
#1
|
|||
|
|||
|
Hi everybody and happy new year,
Is there a way to check if a property used in the XTemplates exists? For example, if I try this: var tpl = new Ext.XTemplate(
'<p>Name: {name}</p>',
'<p>Kids: ',
'<tpl for="kids">',
'<tpl if="age > 1">',
'<p>{name}</p>',
'<p>Dad: {parent.name}</p>',
'</tpl>',
'</tpl></p>'
);
tpl.overwrite(panel.body, data);
Thanks a lot. |
|
#2
|
||||
|
||||
|
I have the same problem (in a "for" loop)
Does anyone have a solution? Thanks |
|
#3
|
||||
|
||||
|
Well, I found a solution, but is it the right one?
If I have an optional property in my objects: for example: the firstname is optional: heroes = [{lastname:"Man", firstname:"Bat"}, {lastname:"Joker"}], I can loop through the array with the following code: new Ext.XTemplate(
'<tpl if="this.exists(heroes)">',
'<fieldset>',
'<legend>My heroes</legend>',
'<tpl for="heroes">',
'{[firstname=""]}',
'<tpl if="this.exists(firstname)">',
'{firstname} ',
'</tpl>',
'{lastname}',
'</tpl>',
'</fieldset>',
'</tpl>',
{
exists: function(o){
return typeof o != 'undefined' && o != null && o!='';
}
});
Thanks for your comment Last edited by efattal; 02-18-2008 at 09:03 AM.. Reason: Precision |
![]() |
| Thread Tools | |
|
|