簡體   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