spring - 根据条件百里香更改 tr 背景颜色
问题描述
我希望根据 th:if 条件更改表格行的背景颜色。
例如:如果预期 != 实际,则 bg = 红色。反之亦然,bg = 绿色。
对于我的示例,我目前有三列——评估类型、预期和实际。评估类型确定预期值和实际值。当前跨度th:style
正确突出显示各个单元格,但我希望<tr>
根据评估使整个突出显示的红色或绿色。
当前代码:
<thead>
<th>Eval Type </th>
<th>Expected </th>
<th>Actual </th>
</thead>
<tbody>
<tr>
<td>
<span th:if="${example.getEvaluationType()} == '1'" th:text="${example.getExpectedcount()}"
th:style="${example.getActualcount()} == ${example.getExpectedcount()} ? 'background: green' : 'background: red'"></span>
<span th:if="${example.getEvaluationType()} == '2'" th:text="${example.getExpectedmb()}"
th:style="${example.getActualmb()} == ${example.getExpectedmb()} ? 'background: green' : 'background: red'"></span>
<span th:if="${example.getEvaluationType()} == '3'" th:text="${example.getExpectedminutes()}"
th:style="${example.getActualminutes()} == ${example.getExpectedminutes()} ? 'background: green' : 'background: red'" ></span>
</td>
</tr>
</tbody>
感谢任何有关问题的帮助或线索,因为我没有找到任何问题。谢谢!
解决方案
对于任何好奇的人:
我最终完成了上面的计算并在我的后端完成了所有这些actual == expected ? 'TRUE' : 'FALSE'
。我将输出分配给单个变量passed
。
将变量和正确的 get/setter 添加到您的程序中,然后此行将使输出能够将整行着色为红色/绿色。
<tr th:style="${taskstatistics.getPassed()} == FALSE ? 'background: red' : 'background: green'">
推荐阅读
- node.js - Runtime.HandlerNotFound aws lambda node.js
- css - 如何使用滚动捕捉 CSS 控制/更改动画的速度?
- python - Tableview 列自动调整
- java - 如何在 Querydsl 中实例化`PostgreSQLQuery`?
- javascript - 在我的 chrome 扩展程序和网站之间共享 cookie
- android - NoSuchMethodError ConstantExpressionEvaluator.evaluateExpression 添加jetpack compose时
- javascript - 为什么 Google Apps 脚本不允许我将我的范围称为变量?
- javascript - React 子组件从传入的内容接收不同的道具
- java - 为什么我的 TicTacToe 的 checkWinner 方法不起作用?
- spring-boot - OpenSource API Gateway 可以支持速率限制/月、API 密钥生成等 API 计划?