繁体   English   中英

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

[英]Conditional Styling with Dash Bootstrap with IF statement

我试图通过使用 Dash bootstrap 和一些 HTML 组件,根据列中的文本值应用两个不同的 colors。 例如,表格看起来像这样。

Value

Yes
No
Yes
Yes
No

如果是“是”,我想将文本的颜色更改为绿色,如果是“否”,则更改为红色。我尝试了以下几行,但似乎 if 语句无法以这种方式工作。

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

尝试三元运算符

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