简体   繁体   English

带 IF 语句的 Dash Bootstrap 的条件样式

[英]Conditional Styling with Dash Bootstrap with IF statement

I'm trying to apply two different colors based on the text value in the column by using Dash bootstrap and some of the HTML components.我试图通过使用 Dash bootstrap 和一些 HTML 组件,根据列中的文本值应用两个不同的 colors。 For example, the table looks like this.例如,表格看起来像这样。

Value

Yes
No
Yes
Yes
No

I want to change the color of the text to green if it's "Yes and to red if it's "No". I tried the following lines but it seems like the if statement doesn't work in this way.如果是“是”,我想将文本的颜色更改为绿色,如果是“否”,则更改为红色。我尝试了以下几行,但似乎 if 语句无法以这种方式工作。

html.Td(
         a["Value"],
         if a["Value"] == "Yes":
              style={"color": "green"},
         else:
              style={"color": "red"},
                                       ) for a in i["Items"]

try Ternary Operators :尝试三元运算符

html.Td(a["Value"],
   style={"color": "green"} if a["Value"] == "Yes" else {"color": "red"})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM