spring-mvc - 在 Thymeleaf 中选中的复选框属性
问题描述
如何使用 Thymeleaf 为表单中的输入设置选中的属性?这是我的代码,目前不起作用:
<label th:each="cat : ${categories}">
<input type="checkbox" value=""
th:value="${cat.id}"
th:text="${cat.description}"
th:checked="${recipe.getCategories().contains(cat) ? true : false}"
/>
</label>
解决方案
如评论中所述,问题可能来自其他地方,但试试这个,看看它是否有帮助:
th:checked="${recipe.getCategories().contains(cat)}"
推荐阅读
- postgresql - 快速获取最后 n 个插入的行
- javascript - 如何从 JSON 表示返回指定类型的对象
- c# - 使用 C# 执行 SELECT 生成的 SQL 以在 SQL Server 上删除多个表时遇到问题
- javascript - How do I attach placeholder to the button through JS' DOM?
- html - 白色文本颜色和白色图像背景颜色问题
- python - 要比较的排名卡
- python - 有没有办法计算图中特定节点周围的集群?
- c - 如何为 png_write_image 准备 RGB 数组和行指针?
- angular - Angular 4 - 第二个 http.get 在 prod 中取消但在本地工作
- python-3.x - 如何访问类变量?