如果tr与百里香一起为空,如何隐藏父div?

Mik*_*hun 0 html javascript css thymeleaf

我正在使用百里香框架。如果值显示为空,我想隐藏整个div。并显示它是否不为null。

HTML代码

<div>
<h2> My Table </h2>
    <table border="1">
        <tr bgcolor="powderblue">
            <th>name</th>
            <th>age</th>
            <th>hobby</th>
            <th>interest</th>
            <th>books</th>
            <th>movie</th>
        </tr>
        <tr th:each="table: ${myTable}">

        <td th:text = "${table.name != null ? table.name : 'NULL'}" />
        <td th:text = "${table.age != null ? table.age : 'NULL'}" />
        <td th:text = "${table.hobby != null ? table.hobby : 'NULL'}" />
        <td th:text = "${table.interest != null ? table.interest: 'NULL'}" />
        <td th:text = "${table.books != null ? table.books : 'NULL'}" />
        <td th:text = "${table.movie != null ? table.movie : 'NULL'}" />

        </tr>
        </table>
</div>
Run Code Online (Sandbox Code Playgroud)

当“ tr th:each =” table:$ {myTable}“未显示任何值时,如何隐藏该div?不必严格地是thymeleaf函数。如果可能,我可以使用angularjs函数。

混乱

我在想做些什么,如果tr标签为null hide div。但是我的第一个tr标签不会为空,因为它是静态的。

输出量

My Table
|name | age | hobby | interest | books | movies |
|     |     |       |          |       |        | 
Run Code Online (Sandbox Code Playgroud)

如果值为null / empty,如何隐藏整体?表值各不相同,并由数据库获得。有时可以为空有时具有值

kar*_*p90 6

如果您使用Thymeleaf 3.xx版,它将为您提供帮助:

<div th:if="${!myTable.isEmpty()}">
...
</div>
Run Code Online (Sandbox Code Playgroud)