我有一个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)
你试过这个吗?
<tpl if="customer == undefined">
<b>{customer}</b>
</tpl>
Run Code Online (Sandbox Code Playgroud)