Thymeleaf。如何根据布尔参数隐藏元素?

huangapple 未分类评论53阅读模式
英文:

Thymeleaf. How to hide element based on boolean parametr?

问题

我有一个评论表格

<table class="table">
    <tbody>
    <tr th:each="review : ${reviewsForMovie}">
        <td th:utext="${review.text}"></td>
    </tr>
    </tbody>
</table>

但如果 review.isApproved == false,我不想显示评论<br>
我该如何做到这一点?

英文:

I have a table of reviews

&lt;table class=&quot;table&quot;&gt;
    &lt;tbody&gt;
    &lt;tr th:each=&quot;review : ${reviewsForMovie}&quot;&gt;
        &lt;td th:utext=&quot;${review.text}&quot;&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

But I dont want to show review if review.isApproved == false<br>
How do i do that?

答案1

得分: 0

<table class="table">
    <tbody>
        <tr th:each="review : ${reviewsForMovie}">
            <td th:hidden="${!review.isApproved}" th:utext="${review.text}"></td>
        </tr>
    </tbody>
</table>
英文:
&lt;table class=&quot;table&quot;&gt;
    &lt;tbody&gt;
    &lt;tr th:each=&quot;review : ${reviewsForMovie}&quot;&gt;
        &lt;td th:hidden=&quot;${!review.isApproved}&quot; th:utext=&quot;${review.text}&quot;&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;/tbody&gt;
&lt;/table&gt;

huangapple
  • 本文由 发表于 2020年4月6日 00:08:22
  • 转载请务必保留本文链接:https://java.coder-hub.com/61045504.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定