2017-04-13 1380 views
-1

我正在使用thymeleaf框架。我想隐藏整个div,如果价值是空的。并显示它是否为空。如果tr与thymeleaf一起是空的,如何隐藏父div?

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> 

如何隐藏这个div时, “TR日:每个=” 表:$ {myTable的}”没有显示任何值,它不必是严格thymeleaf功能。如果可能的话,我可以使用angularjs功能。

混乱

我的想法做一些事情一样,如果tr标签是空隐藏的div,但我的第一个tr标签会不是空的,因为它是静态的。

输出

My Table 
|name | age | hobby | interest | books | movies | 
|  |  |  |   |  |  | 

我怎么能隐藏整如果值是空/空?表值由数据库变化并获得。有时可以是空白如果您在使用Thymeleaf 3.xx版有时有值

+0

检查是否为myTable为空或没有,这真是小巫见大巫 – charlietfl

+0

我买了我的困惑我明白自己的命名约定。谢谢。 –

回答

1

,这将帮助你:

<div th:if="${!myTable.isEmpty()}"> 
... 
</div>