View Full Version : Json and XTemplate question

21 Apr 2009, 12:02 PM

I generate my json dynamically and if my object has empty fields, it will ignore them and therefore reducing the amount of text sent back to the client. Now, I get stuck when I am creating an Xtemplate because I wouldn't know if those properties exist or not and my question is: Is there a way to check before hand if they exist?
This is my Json:

"Header":"Dependent Information",
"Name":"JANE DOE",
}This is my JS:

var tpl2 = new Ext.XTemplate(
'<div class="session-hd">',
'<tpl if="this.isEmpty(Name)== false">',
'<p>Name: {Name}</p>',
'<tpl if="this.isEmpty(ID) == false">',
'<p>ID: {ID}</p>',
'<tpl if="this.isEmpty(Address)== false">',
'<p>Address: {Address}</p>',
'<tpl if="this.isEmpty(CSZ)== false">',
'<tpl if="this.isEmpty(Date)== false">',
'</div>', {
isEmpty: function(value){
if (value=='null')
return true
else return false

Thank you

21 Apr 2009, 1:41 PM