可以根据后端代码中的数据列表来动态生成下拉选项。可以使用Thymeleaf模板引擎的语法来遍历数据列表,生成对应的

下拉框的HTML代码可以修改如下:

<select name="nodeList" class="form-control dual_select" th:with="type=${nodeList}" required>
    <option value="">请选择</option>
    <option th:each="nodeModelNo : ${type}" th:text="${nodeModelNo}" th:value="${nodeModelNo}"></option>
</select>

这样,通过Thymeleaf的th:each指令,可以遍历nodeList数据列表,生成对应的

需要注意的是,如果需要设置默认选中的选项,可以在后端代码中设置一个selected属性,然后在Thymeleaf模板中根据该属性来设置对应


原文地址: https://www.cveoy.top/t/topic/i0Y5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录