您可以尝试以下方法来设置初始选择的项目:

  1. 将初始选择的项目添加到 select 元素的'selected'属性中:
<select name="keyModelList" multiple="multiple" size="10" class="form-control dual_select" required>
    <option th:each="dict : ${type}" th:text="${dict.modelNo}" th:value="${dict.modelNo}" selected></option>
</select>
  1. 通过 JavaScript 在初始化之后使用'bootstrapDualListbox'方法来设置初始选择的项目:
$('.dual_select').bootstrapDualListbox({
    // other options...
}).bootstrapDualListbox('setSelected', ['item1', 'item2', 'item3']);

请注意,您需要确保在初始化之后使用'bootstrapDualListbox'方法调用'setSelected'方法。

希望能帮到您!

标签: 常规


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