我使用Ext.XTemplate在列表中显示我的数据,我想实现一个函数,当我得到一个正数时,它显示为红色和绿色。
为了实现这个功能,我创建了两种样式,并希望传递参数来动态创建这样的模板
currentControl.balanceResultTpl +='<div class="{[{'+AVAILABLE_QTY+'} > 0 ?"summary-qty-style-red":"summary-qty-style-green"]}">{'+AVAILABLE_QTY+'}/{'+QTY+'}</div></div>';参数AVAILABLE_QTY在存储中,使用此模板时将设置值。
然而,判断声明似乎不起作用,我很困惑。
我在sencha文档里查过,但没有发现对我的案子有用的东西。
谢谢!
发布于 2015-06-19 02:31:13
var tpl = new Ext.XTemplate(
'<div class="',
'<tpl if="AVAILABLE_QTY > 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>https://stackoverflow.com/questions/30928823
复制相似问题