js:
$().ready(function() {
var type=$("#setList").val();
$('#feeCyfkxm option').each(function () {
if (type.indexOf(''+this.value+'')!=-1)this.selected=true;
});
});
<label class="col-sm-3 control-label">冲预收款项目:</label>
<div class="col-sm-3">
<input type="hidden" th:value="${setLists}" id="setLists">
<input type="hidden" th:value="${set.feeCyfkxm}" id="setList">
<input type="hidden" th:value="${feeCyfkxmList}" id="feeCyfkxmList">
<select id="feeCyfkxm" name="feeCyfkxm" lay-verify="required" class="form-control " multiple="multiple">
<option th:each="hall : ${setList}" th:value="${hall.id}" th:text="${hall.feeName }"
></option>
</select>
</div>
Java
//判读 冲抵项目的id集合
List<SetDO> feeCyfkxmList=new ArrayList<SetDO>();
String s=set.getFeeCyfkxm();
StringBuffer names=new StringBuffer();
if(s==""||s==null){ }else{
String[] ss=s.split(",");
if(ss.length>0){
for(String ids:ss){
SetDO se = setService.get(Integer.parseInt(ids));
feeCyfkxmList.add(se);
}
}
}
model.addAttribute("feeCyfkxmList", feeCyfkxmList);
item_mode = ','+item_mode+','; //从后台传过来的值 $('.mode_type option').each(function () { if (item_mode.indexOf(','+this.value+',')!=-1)this.selected=true; }); //重新加载
$('.selects').multipleSelect();