我使用Java、Spring和Thymeleaf。我试图制作一个表格,列出以下数据,每个人在一行中。
<tr class="tr-frame" id="tr-one-line" th:each="woundedPerson: ${woundedPeople}"> <td class="td-ident" th:text="${woundedPerson.getIdent()}"></td> <td class="td-name" th:text="${woundedPerson.getName()}"></td> <td class="td-surname" th:text="${woundedPerson.getSurname()}"></td> <td class="td-index" id="td-ind" th:text="${woundedPerson.getColorIndex()}"></td> <td class="td-date-time" th:text="${woundedPerson.getAddAt()}"></td> </tr>
我想知道,如何根据th:text=“${woundedPerson.getColorIndex()}”的值更改行的颜色?值可以是红色、绿色、黑色和黄色。需要帮忙吗?
你还没有提到受伤者的价值观。getColorIndex()。
您可以使用th:classappend在tr标记上添加一个类
<tr th:classappend="${woundedPerson.getColorIndex() == 'blue' ? 'class_name' : 'different_class_name'}" >
还是一种风格
<tr th:style="${woundedPerson.getColorIndex() == 'blue' ? 'background-color:blue' : ''}" >