在下拉列表中预先选择默认值
问题描述:
我在Thymeleaf中创建了一个下拉列表,它功能正常。不过,我也希望在下拉列表中选择一个选项。在下拉列表中预先选择默认值
这里是我到目前为止的代码:
<select id="selectOptions" th:field="*{selectedOption}">
<option th:each="option : ${searchOptions}"
th:value="${option.getOption()}"
th:text="${option.getOptionName()}">Options</option>
</select>
我将如何使用th:selected
标签与此?在他们的网站上我没有看到任何文档。
感谢
答
<select id="selectOptions" th:field="*{selectedOption}">
<option th:each="option : ${searchOptions}"
th:value="${option.getOption()}"
th:selected="${option.someOption()}" // <- use the th:selected
th:text="${option.getOptionName()}">Options</option>
</select>