Extjs Ext JS xtemplate问题-检查字段是否存在

Extjs Ext JS xtemplate问题-检查字段是否存在,extjs,Extjs,我有一个ExtJS xtemplate,由于json对象的返回方式而引发错误 有时json对象定义了一个字段customer,但有时对象中完全没有该字段 显然,当将模板应用于缺少字段的json时,我会遇到一个错误customer is not defined 所以我的问题是: 是否有一种方法可以检查xtemplate中的未定义字段 比如: {customer} 很明显,我试过这个,但不起作用 谢谢你的帮助。你试过这个吗 <tpl if="customer == undefined">

我有一个ExtJS xtemplate,由于json对象的返回方式而引发错误

有时json对象定义了一个字段
customer
,但有时对象中完全没有该字段

显然,当将模板应用于缺少字段的json时,我会遇到一个错误customer is not defined

所以我的问题是:
是否有一种方法可以检查xtemplate中的未定义字段

比如:

{customer}
很明显,我试过这个,但不起作用

谢谢你的帮助。

你试过这个吗

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

{客户}

除非我弄错了,否则您应该可以执行以下操作:

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

仅对我有效:{[values.customer?values.customer:'Empty']}否则我会收到错误:[INFO][Ext.XTemplate#apply]错误:未定义客户这也会有效:
{[values.customer | |'Empty']}
如果仅在定义了它的情况下才需要写出它,那么这是如何工作的?
<tpl if="customer">
   <b>{customer}</b>
</tpl>
{[values.customer]}
{[values.customer ? customer : 'Empty']}