问题
I have the following Xtemplate code:
('Ext.XTemplate',
'<div class="moreArrow"></div>',
'<div class="img"><img src="http://localhost/WL2/assets/rest/{image}"/></div>',
'<div class="meta">',
'<h3>{merchName}</h3>',
'<div class="actions">',
'<button class="seen{[values.seen ? " selected" : ""]}">{action}</button>',
'{% if (values.seen) { %}',
'<button class="thumb up{[values.like ? " selected" : ""]}"><b></b></button>',
'<button class="thumb down{[values.dislike ? "selected" : ""]}"><b></b> </button>',
'{% } else { %}',
'<button class="want{[values.wantToSee ? "selected" : ""]}">Want to Go There</button>',
'{% } %}',
'</div>',
'</div>'
)
My problem is that the if condition in the part {% if (values.seen) { %}
is not working, that is when the button is clicked, it should show two buttons of dislike and like. What is wrong with my code that is causing this issue?
回答1:
It might not be working because you are not comparing it with anything.
BTW, here are few examples to understand how to use if condition:
Using comparison operators:
<tpl if="totalDiscount > 0">
Using 'AND' operator
<tpl if="active == true && available == true">
Using XTemplates variables:
'{% if (xindex % 2 === 1) { %}' +
'<div>Odd Row</div>' +
'{% } %}'
回答2:
I don't think you're using XTemplate correctly. Check out documentation page and try to replace your conditions with <tpl if>
tag
来源:https://stackoverflow.com/questions/16057703/xtemplate-if-conditions-in-sencha-touch