效果如图:
一、HTML代码
<label class="col-sm-1 control-label text-right" for="ds_host">
科室:</label>
<div class="col-sm-3">
<select id="sl_ks" class="selectpicker" data-live-search="false" multiple="multiple">
<option value="" selected="selected">全部</option>
</select>
</div>
二、js绑定值
$.ajax({
type: 'get',
url: 'jgdx.ashx?action=bindBm',
dataType: 'json',
success: function (datas) {//返回list数据并循环获取
var select = $("#sl_ks");
for (var i = ; i < datas.length; i++) {
select.append("<option value='" + datas[i].id + "'>"
+ datas[i].gzbm + "</option>");
}
$('#sl_ks.selectpicker').selectpicker('val', '');
$('#sl_ks.selectpicker').selectpicker('refresh');
}
});
三、后台构造的json格式
[{"gzbm":"办公室","id":""},
{"gzbm":"领导班子","id":""},
{"gzbm":"研发部","id":""},
{"gzbm":"后勤部","id":""},
{"gzbm":"质检部","id":""},
{"gzbm":"媒介部","id":""}]