【发布时间】:2021-07-07 20:17:02
【问题描述】:
我想根据数据库中的值更改按钮颜色。 我正在使用此代码:
{% if result %}
{% for of in result %}
<a data-container="body" data-toggle="popover" data-placement="right" data-content='NO OF: {{of.0}} _ Jour ATT: {{of.2.days}} _ Date Entrée: {{of.1}} '>
<span class="{% if '{{of.2}}' > 2 %} dot red {% endif %}
{% elif '{{of.2}}' == 2 %}dot red {% endif %}
{% else %}dot{% endif %}"></span>
</a>
{% endfor %}
{% else %}
<p>Encours Vide</p>
{% endif %}
我也用过:
<a data-container="body" data-toggle="popover" data-placement="right" data-content='NO OF: {{of.0}} _ Jour ATT: {{of.2.days}} _ Date Entrée: {{of.1}} '>
{% if '{{of.2}} >=3' %}<span class="dot red"></span>
{% elif '{{of.2}} ==2' %}<span class="dot yellow"></span>
{% else %}<span class="dot"></span> {% endif %} </a>
两者都不起作用,如何正确检查我的 html 代码中的值列表?
Views.py:
result=Poste.objects.filter(Nom_poste='MGP1').values_list('OF__Numero_Of','OF__Date','OF__Nbre_jr')
PS:我也使用了{{of.2.days}},因为Nbre_jr 是DurationField
点的css代码:
.dot {height: 30px; width: 30px;background-color: #0f5132;border-radius:50%;display:inline-block;}
.red{background-color:#d00000;}
.yellow{background-color: #ffc107;}
我不知道如何在 JS 中执行此操作,因此尝试简化我的代码。有什么建议吗?
【问题讨论】:
标签: javascript python html css django