gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 03:08:33 25 4
gpt4 key购买 nike

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

有时 json 对象定义了一个字段 customer,但有时该对象完全缺少该字段。

显然,当我将模板应用于缺少字段的 json 时,我收到错误未定义客户

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

喜欢:

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

显然我已经尝试过这个,但它不起作用。

感谢您的帮助。

最佳答案

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

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

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

{[values.customer]}
{[values.customer ? customer : 'Empty']}

关于extjs - Ext JS xtemplate 问题 - 检查字段是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1608570/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com