如何在Odoo模板语言中使用if
我尝试使用与Django相同的功能:如何在Odoo模板语言中使用if,odoo,odoo-8,odoo-website,Odoo,Odoo 8,Odoo Website,我尝试使用与Django相同的功能: 在奥多,我有: 如果“c.id=cat_id”,我需要附加类“active” 奥多是怎么做到的 我正在使用: 但是寻找一种更具python风格的方式我甚至不认为QWeb模板是python风格的;) 如果需要,您可以这样做: <a t-attf-href="/downloads/{{c.id}}" t-attf-class="list-group-item {{ 'active' if c.id == category_id else ''
在奥多,我有:
如果“c.id=cat_id”,我需要附加类“active”
奥多是怎么做到的
我正在使用:
但是寻找一种更具python风格的方式我甚至不认为QWeb模板是python风格的;) 如果需要,您可以这样做:
<a t-attf-href="/downloads/{{c.id}}" t-attf-class="list-group-item {{ 'active' if c.id == category_id else '' }}">
<t t-esc="c.name"/>
</a>
尝试以下操作:
在小部件中准备一个函数来比较两个值,并将css样式设置为该小部件的新属性
init: function(parent,options){
//define 1 property to access this in template and set it from calling function
this.style = '';
this._super(parent,options);
}
get_comparison_result : function(cid,category_id){
var style = "";
if (cid != category_id){
//Add style here
style = "background-color:white";
}
else{
//Add style here
style = "background-color:green";
}
this.style = style;
return true;
}
然后您可以从模板中调用它,并将结果分配给变量,然后使用该结果
<t t-if="widget.get_comparison_result(c.id, category_id)">
<t t-set="style" t-value="widget.style" />
</t>
<a t-attf-href="/downloads/{{c.id}}" t-att-style="style"><t t-esc="c.name"/>
Ludwik Trammer奥多大师!