开发者

Ext JS xtemplate question - check if field exists

开发者 https://www.devze.com 2022-12-09 08:42 出处:网络
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

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 applyin开发者_运维知识库g 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:

<tpl if="customer!=undefined">{customer}</tpl>

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

Thanks for any help.


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']}


Have you tried this?

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

精彩评论

暂无评论...
验证码 换一张
取 消