2016-11-16 51 views
0

为什么我使用下面的代码时,我的百里香叶产生了如此大的差距。Thymeleaf餐桌如何创造差距?

BAD/WARNING 
</h3> 
<h3> 
APPLICATION PROCESSING 
</h3> 
<table class="tablebad"> 
    <tr> 
     <th> Status </th> 
     <th> HostName </th> 
     <th> Process Name </th> 
     <th> Process Count </th> 
    </tr> 
     <tr th:each="DartModel, iterStat : ${countlist}"> 
     <td th:if ="${DartModel.Status == 'BAD'}" th:text="${DartModel.Status}"></td> 
     <td th:if="${DartModel.Status == 'BAD'}" th:text="${DartModel.host}"></td> 
     <td th:if="${DartModel.Status == 'BAD'}" th:text="${DartModel.processName}"></td> 
     <td th:if="${DartModel.Status == 'BAD'}" th:text="${DartModel.processCount}"></td> 
     </tr> 

</table> 


<h3> 
APPLICATION PROCESSING 
</h3> 

<table class="tableok"> 
    <thead> 
    <tr> 
     <th> Status </th> 
     <th> HostName </th> 
     <th> Process Name </th> 
     <th> Process Count </th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr th:each="DartModel, iterStat : ${countlist}"> 
     <td th:if="${DartModel.Status == 'OK'}" th:text ="${DartModel.Status}"></td> 
     <td th:if="${DartModel.Status == 'OK'}" th:text="${DartModel.host}"></td> 
     <td th:if="${DartModel.Status == 'OK'}" th:text="${DartModel.processName}"></td> 
     <td th:if="${DartModel.Status == 'OK'}" th:text="${DartModel.processCount}"></td> 
    </tr> 
    </tbody> 
</table> 

结果 Output

下,这将是我的所有数据与 “OK” 的状态中打印出来。我最终试图根据价值对数据进行排序。我尝试使用javascript/jquery,但它太复杂了。我找到了一种基于值拆分数据行的方法。如果数值是“坏”显示表上面反之亦然值与“好” 我是否做错了? I

回答

1

问题是,您正在将th:if放在<td>元素上而不是<tr>上。这意味着你的HTML看起来像这样(你有每个非空行之间有一些空行

<table> 
    <tr> 
     <td>BAD</td> 
     <td>...</td> 
     <td>...</td> 
    </tr> 

    <tr></tr> 
    <tr></tr> 

    <tr> 
     <td>BAD</td> 
     <td>...</td> 
     <td>...</td> 
    </tr> 

    <tr></tr> 
</table> 

你应该只移动th:if<tr>元素,像这样:

<table class="tablebad"> 
    <tr> 
     <th>Status</th> 
     <th>HostName</th> 
     <th>Process Name</th> 
     <th>Process Count</th> 
    </tr> 

    <tr th:each="DartModel, iterStat : ${countlist}" th:if="${DartModel.Status == 'BAD'}"> 
     <td th:text="${DartModel.Status}" /> 
     <td th:text="${DartModel.host}" /> 
     <td th:text="${DartModel.processName}" /> 
     <td th:text="${DartModel.processCount}" /> 
    </tr> 
</table> 
+0

哇,谢谢!,但是为什么当我把它放在​​标签下时会导致空行?再次感谢! – Jesse

+0

我在回答的开头解释了它,如果你把它放在'​​'而不是''上,你在每行数据之间有一堆空行表格 – Metroids

+0

是否可以在div标签上使用此逻辑?如果Stats =“Critical”,则显示div – Jesse