You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo 13:如何基于Qweb实现看板视图选择字段的颜色化显示?

看板视图优先级颜色不生效的解决方案

问题根源

你的代码存在两个关键问题导致颜色不生效:

  1. 拼写错误:判断条件里的critial是笔误,正确值应为critical
  2. 样式未应用:仅定义了style变量,但没有将其绑定到显示优先级的元素上

修正后的看板视图代码

<record id="todo_kanban" model="ir.ui.view">
    <field name="name">todo.kanban</field>
    <field name="model">todo</field>
    <field name="arch" type="xml">
        <kanban default_group_by="stage_id" class="o_kanban_small_column o_kanban_project_tasks" on_create="quick_create">
            <field name="todo_id"/>
            <field name="user_id"/>
            <field name="priority"/>
            <templates>
                <t t-name="kanban-box">   
                    <div class="oe_kanban_details">
                        <strong class="o_kanban_record_title"><field name="todo_id"/></strong>
                        <div class="o_kanban_tags_section"/>
                        <ul>
                            <li>User : <field name="user_id"/></li>
                            <li>Priority : 
                                <span t-att-style="priority == 'critical' ? 'color:red' : priority == 'urgent' ? 'color:orange' : 'color:green'">
                                    <field name="priority"/>
                                </span>
                            </li>
                        </ul>
                    </div>
                </t>
            </templates>
        </kanban>
    </field>
</record>

关键修改说明

  • 修复了critical的拼写错误
  • 使用<span>包裹优先级字段,通过t-att-style属性直接根据优先级值绑定对应样式,确保样式生效
  • 采用三元表达式替代多个t-if判断,代码更简洁高效

如果你偏好原有的t-set写法,也可以这样调整(确保样式被应用):

<li>Priority : 
    <t t-set="style" t-value="priority == 'critical' ? 'color:red' : priority == 'urgent' ? 'color:orange' : 'color:green'"/>
    <span t-att-style="style">
        <field name="priority"/>
    </span>
</li>

内容的提问来源于stack exchange,提问作者for-loop

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 00:05:24