我如何使用 if-else 语句动态选择 div class?

How could I dynamically choose a div class with an if-else statement?

我用Ext.XTemplate在列表中显示我的数据,我想实现一个功能,当我得到一个正数时,它显示为红色和绿色。

为了实现这个功能,我创建了两个样式,我想传递参数来动态创建这样的模板

currentControl.balanceResultTpl +='<div class="{[{'+AVAILABLE_QTY+'} &gt; 0 ?"summary-qty-style-red":"summary-qty-style-green"]}">{'+AVAILABLE_QTY+'}/{'+QTY+'}</div></div>';

参数 AVAILABLE_QTY 已存储,将在使用此模板时设置值。

但是判断语句好像不行,一头雾水

我查阅了 sencha 文档,但没有找到对我的情况有用的东西。

谢谢!

var tpl = new Ext.XTemplate(
                '<div class="',
                    '<tpl if="AVAILABLE_QTY &gt; 0">',
                        'summary-qty-style-red',
                    '<tpl else>',
                        'summary-qty-style-green',
                    '</tpl>',
                '">{AVAILABLE_QTY}/{QTY}</div>'
            );
console.log(tpl.apply({AVAILABLE_QTY: -1, QTY: 5}));
console.log(tpl.apply({AVAILABLE_QTY: 1, QTY: 5}));

输出:

<div class="summary-qty-style-green">-1/5</div>
<div class="summary-qty-style-red">1/5</div>