用thymeleaf用标签给页面select下拉框赋值怎么实现
1个回答
展开全部
官方上实现步骤如下:
<select th:field="*{paymentMethod}" th:remove="all-but-first">
<option th:each="paymentMethod : ${paymentMethods}"
th:value="${paymentMethod}" th:text="${paymentMethod.description}">Credit card</option>
<option>Another payment method</option>
<option>Another payment method</option>
</select>
还可以用以下方法实现:
<select multiple="multiple" class="width-50 chosen-select" name="knowledgePointIdSet" data-placeholder="分类名称:">
<option th:each="category:${knowPointList}" th:value="${category.id}"
th:selected="${#strings.contains(instance.knowledgePointIdSet,category.id)}"
th:text="${category.name}" >性名:</option>
</select>
<select th:field="*{paymentMethod}" th:remove="all-but-first">
<option th:each="paymentMethod : ${paymentMethods}"
th:value="${paymentMethod}" th:text="${paymentMethod.description}">Credit card</option>
<option>Another payment method</option>
<option>Another payment method</option>
</select>
还可以用以下方法实现:
<select multiple="multiple" class="width-50 chosen-select" name="knowledgePointIdSet" data-placeholder="分类名称:">
<option th:each="category:${knowPointList}" th:value="${category.id}"
th:selected="${#strings.contains(instance.knowledgePointIdSet,category.id)}"
th:text="${category.name}" >性名:</option>
</select>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询