百里香叶显示表的前k行

时间:2015-03-19 10:02:13

标签: html thymeleaf

我有一张桌子和一条多线数据集。我不想跨越这个表的所有行。所以我创建了一个计数器,但是我在if条件下出错:

<div th:if="${dataset}" th:with="counter=0">

    <table class="table">
        <tbody>
        <th:block th:each="t_log : ${dataset.rows}" th:with="counter=${counter} + 1">

            <tr th:if="${counter <= 5 }">
                <td th:text="${t_log.title}"/>
                <td th:if="${t_log.msg == '1'}" th:text="Online"/>
                <td th:if="${t_log.msg == '0'}" th:text="Offline"/>
            </tr>
        </th:block>
        </tbody>
    </table>
</div>

我从这里看到了一个例子:

http://forum.thymeleaf.org/Displaying-an-iterable-of-n-items-in-rows-of-3-items-with-thymeleaf-td4025738.html

但是我的计数器不能解决问题。

1 个答案:

答案 0 :(得分:1)

试试这个Thymeleaf有一个内置计数属性。请参阅文档6.2 http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html以及结帐部分4.9您可能需要将<=更改为le;

<div th:if="${dataset}">

    <table class="table">
        <tbody>
        <th:block th:each="t_log,count : ${dataset.rows}">

            <tr th:if="${count <= 5 }">
                <td th:text="${t_log.title}"/>
                <td th:if="${t_log.msg == '1'}" th:text="Online"/>
                <td th:if="${t_log.msg == '0'}" th:text="Offline"/>
            </tr>
        </th:block>
        </tbody>
    </table>
</div>
相关问题