bootstrap-select 回显多个选中值
效果展示
-
后台返回的数据 dictionaryList 全部下拉选 ,areaList选中的下拉选
@RequestMapping("/updatedAdministratorView")
public ModelAndView updatedAdministratorView(Integer id) {
ModelAndView result = new ModelAndView("/authority/updateAdministrator");
SysUser authorityUser =authorityService.updatedAdministratorView(id);
List list =authorityService.administratorView();
List authorityGroupUser=authorityService.selectGroup(authorityUser.getId());
List list1 =authorityService.selectSysArea();
List list2 =authorityService.selectSysUserArea(authorityUser.getId());
result.addObject(“dictionaryList”, JSONArray.fromObject(list1).toString());
result.addObject(“areaList”, JSONArray.fromObject(list2).toString());
result.addObject(“authorityGroupUser”, authorityGroupUser);
result.addObject(“groupList”, list);
result.addObject(“authorityUser”, authorityUser);
return result;
}
2.js代码
<select class="selectpicker m-b" multiple data-live-search="true" id="areaCode" name="areaCode"> <%-- <c:if test="${not empty dictionaryList}"> <c:forEach items="${dictionaryList}" var="projectInfo" varStatus="i"> <option value="${projectInfo.code}">${projectInfo.value}</option> </c:forEach> </c:if> --%> </select> </div>
3.js代码
var valueArr=[];
var dictionaryList = eval(’(’ + ‘
d
i
c
t
i
o
n
a
r
y
L
i
s
t
′
+
′
)
′
)
;
v
a
r
a
r
e
a
L
i
s
t
=
e
v
a
l
(
′
(
′
+
′
{dictionaryList}' + ')'); var areaList = eval('(' + '
dictionaryList′+′)′);varareaList=eval(′(′+′{areaList}’ + ‘)’);
//已选中大区
var selectArr=[];
var str="";
for(var i=0;i<dictionaryList.length;i++){
str=str+""+dictionaryList[i].value+"";
}
for(var i=0;i<areaList.length;i++){
selectArr.push(areaList[i].area_code);
}
console.log(str);
$("#areaCode").html(str);
$("#areaCode").selectpicker(‘val’, selectArr);
// 刷新
$(’#areaCode’).selectpicker(‘refresh’);