tags:

views:

2647

answers:

2

Hi, I have an extjs xtemplate that is throwing errors because of the way a json object is returned. Sometimes the json object has a field 'customer' defined, but sometimes it's completely missing from the object. obviously, i get an error 'customer is not defined' when applying my template to the json where the field is missing.

so my question is: is there a way that i can check for an undefined field in an xtemplate ? like : ' {customer} '

obviously i've tried this but it doesn't work.

Thanks for any help.

+1  A: 

Have you tried this?

<tpl if="customer == undefined">
    <b>{customer}</b>
</tpl>
Robert Koritnik
this worked. thanks :)
29er
A: 

Unless I'm mistaken, you should just be able to do something like the following:

<tpl if="customer">
   <b>{customer}</b>
</tpl>

Alternatively, you should be able to embed (albeit limited, not sure if my ternary example will work as expected) Javascript into XTemplates like so:

{[values.customer]}
{[values.customer ? customer : 'Empty']}
RyanTheDev
this worked too. thanks!!
29er