簡體   English   中英

遍歷列表中的列表並顯示在表格中

[英]Iterate through list in a list and show in table

我在列表中有一個列表,它看起來像:

List<List<Integer>> coverage

在我的控制器中,我將它交給模型。 在我的模板中,我想遍歷列表中的整數列表並在1表中顯示。

<table class="table table-hover table-bordered">
    <tr>
        <td class="table-colspan" colspan="1" >1</td>
        <td class="table-colspan" colspan="1" >2</td>
        <td class="table-colspan" colspan="1" >3</td>
        <td class="table-colspan" colspan="1" >4</td>
        <td class="table-colspan" colspan="1" >Total</td>
        <td class="table-colspan" colspan="1" >6</td>

    </tr>
    <tr class="title-tr" th:each="list : ${coverage}">
        <tr class="title-tr" th:each="r, iterationStatus : ${list}">
            <tr th:text="${r}"></tr>
            <td th:text="${r}" ></td>
            <td th:text="${r}"></td>
            <td th:text="${r}"></td>
            <td th:text="${r}"></td>
            <td th:text="${r}"></td>
        </tr>
    </tr>
</table>

我首先遍歷List以獲取每個List<Integer>之后我遍歷List<Integer>本身來查看整數。 但是List<Integer>每個整數都有自己的行。 所以List<Integer>的第一個整數出現了6次。

我怎樣才能解決這個問題?

我希望我的情況足夠清楚,否則我會提供更多信息。 提前致謝。

問題是,您要包括tr其他標記內tr標簽。 如果要遍歷列,請將其更改為:

<tr class="title-tr" th:each="list : ${coverage}">
   <td th:each="r, iterationStatus : ${list}" th:text="${r}">
   </td>
</tr>

PS因為我不太清楚你想要實現什么,只需另一個提示:如果你想迭代tr ,使用th:block wrapper而不是將tr包含到另一個tr

   <th:block th:each="list : ${coverage}"> 
       <tr th:each="r : ${list}"> ... </tr>
   </th:block>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM