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

29e*_*9er 8 extjs

我有一个ExtJS xtemplate因为返回json对象的方式而抛出错误.

有时json对象customer定义了一个字段,但有时它完全从对象中丢失.

显然,我得到一个错误,在将模板应用到缺少字段的json时,未定义客户.

所以我的问题是:
有没有办法可以检查xtemplate中的未定义字段?

喜欢:

<tpl if="customer!=undefined">{customer}</tpl>
Run Code Online (Sandbox Code Playgroud)

很明显我已经尝试过了,但它不起作用.

谢谢你的帮助.

Rya*_*Dev 13

除非我弄错了,否则你应该只能做以下事情:

<tpl if="customer">
   <b>{customer}</b>
</tpl>
Run Code Online (Sandbox Code Playgroud)

或者,您应该能够嵌入(尽管有限,不确定我的三元示例是否会按预期工作)Javascript进入XTemplates如下:

{[values.customer]}
{[values.customer ? customer : 'Empty']}
Run Code Online (Sandbox Code Playgroud)

  • 对我来说只有作品:{[values.customer?values.customer:'empty']}否则我收到错误:[INFO] [Ext.XTemplate #apply]错误:客户未定义 (2认同)

Rob*_*nik 5

你试过这个吗?

<tpl if="customer == undefined">
    <b>{customer}</b>
</tpl>
Run Code Online (Sandbox Code Playgroud)