【发布时间】:2015-04-13 19:43:58
【问题描述】:
我一直在玩弹簧靴和百里香;我正在尝试制作一个表格,我将在其中列出数字并由用户选择它们;但是我想“检查”第三个元素(当等于 3 时),但我看不到输入已被检查。
我在加载信息和显示复选框时没有问题,当我想在页面加载时默认选中其中一个时出现问题。
我需要一些帮助来确定应该是什么问题,或者它是否是 th:checked 属性的错误。
我在控制器中有这个
@ModelAttribute("allFeatures")
public List<Integer> populateFeatures() {
return Arrays.asList(1, 2, 3, 4, 5, 6);
}
这里是html代码
<ul>
<li th:each="feat : ${allFeatures}">
<input type="checkbox" th:field="*{features}" th:value="${feat}" th:checked="${feat == 3}"></input>
<label th:for="${#ids.prev('features')}" th:text="${'seedstarter.feature.' + feat}">Electric Heating</label>
</li>
<li th:remove="all">
<input id="removed1" type="checkbox"/> <label for="removed1">Turf</label>
</li>
</ul>
提前致谢。
【问题讨论】:
-
您是否尝试过使用另一种语法:<... th:checked="${feat} == 3"> ?
标签: spring-boot thymeleaf