html - Thymeleaf:循环后删除包含迭代属性(th:each)或评估后包含条件属性(th:if)的div
问题描述
在 Thymeleaf 中,是否有可能delete
包含wrapper div
条件循环?假设 SpringBoot 应用程序中的以下代码,我打算在评估条件并循环遍历错误列表后擦除第一个和第二个 div。
<div th:if="${errors != null}">
<div th:each="error : ${errors}">
<div th:utext="${error}"></div>
</div>
</div>
我喜欢在不使用 JavaScript 的情况下实现这一点。
解决方案
您也可以使用 a <th:block />
(未呈现)。此外,无需将迭代和文本分开。您应该能够像这样生成相同的代码:
<th:block th:if="${errors != null}">
<div th:each="error : ${errors}" th:utext="${error}" />
</th:block>
(我更喜欢<th:block />
。th:remove="tag"
)
推荐阅读
- react-native - 反应原生 FlatList 不显示图像
- email - 基于单元格值的电子邮件通知。无法对所有行应用脚本功能
- tsql - 合并 - 匹配时什么都不做
- python - Python - 天蓝色 python 脚本任务出错 - ##[error]C:\ProgramData\Anaconda3\python.exe 失败,返回码:0
- sql - SQL Query 在多个中执行 IN
- r - 如何使用子集函数中的运算符删除 R 中的记录?
- sql-server - 是否可以恢复数据库并保留从以前的数据库登录的安全权限?
- javascript - 如何从 Google Apps 脚本中的压缩 blob 中恢复 JSON 字符串?
- c# - 从异步方法更新标签/文本块
- powershell - PowerShell命令移动到根目录