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


i use ext.xtemplate show data in list , want realize function when positive number, show red , green when negative.

to realize function, create 2 style , want pass parameters dynamically create template this

currentcontrol.balanceresulttpl +='<div class="{[{'+available_qty+'} &gt; 0 ?"summary-qty-style-red":"summary-qty-style-green"]}">{'+available_qty+'}/{'+qty+'}</div></div>'; 

the parameter available_qty in store , value set when template used.

however, judgement statement seems don't work , confused.

i have looked in sencha docs found nothing useful case.

thanks!

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})); 

outputs:

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

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -