tBSTAR
21 Apr 2009, 12:02 PM
Hi,
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:
"DependentInformation":{
"Header":"Dependent Information",
"Name":"JANE DOE",
"ID":"YLN0000002",
"DOB":"01/06/1978"
}This is my JS:
var tpl2 = new Ext.XTemplate(
'<div class="session-hd">',
'<tpl if="this.isEmpty(Name)== false">',
'<p>Name: {Name}</p>',
'</tpl>',
'<tpl if="this.isEmpty(ID) == false">',
'<p>ID: {ID}</p>',
'</tpl>',
'<tpl if="this.isEmpty(Address)== false">',
'<p>Address: {Address}</p>',
'<tpl if="this.isEmpty(CSZ)== false">',
'<p>{CSZ}</p>',
'</tpl>',
'<tpl if="this.isEmpty(Date)== false">',
'<p>{Date}</p>',
'</tpl>',
'</div>', {
isEmpty: function(value){
if (value=='null')
return true
else return false
}}
);
Thank you
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:
"DependentInformation":{
"Header":"Dependent Information",
"Name":"JANE DOE",
"ID":"YLN0000002",
"DOB":"01/06/1978"
}This is my JS:
var tpl2 = new Ext.XTemplate(
'<div class="session-hd">',
'<tpl if="this.isEmpty(Name)== false">',
'<p>Name: {Name}</p>',
'</tpl>',
'<tpl if="this.isEmpty(ID) == false">',
'<p>ID: {ID}</p>',
'</tpl>',
'<tpl if="this.isEmpty(Address)== false">',
'<p>Address: {Address}</p>',
'<tpl if="this.isEmpty(CSZ)== false">',
'<p>{CSZ}</p>',
'</tpl>',
'<tpl if="this.isEmpty(Date)== false">',
'<p>{Date}</p>',
'</tpl>',
'</div>', {
isEmpty: function(value){
if (value=='null')
return true
else return false
}}
);
Thank you