使用bootstrap的selectpicker时,二级联动一直不展示其他选项。
<div class="col-sm-1">
<select id="province_code" data-style="btn-success btn-outline" class="selectpicker" onchange="getCity()">
<option value="">请选择(必选)</option>
</select>
</div>
解决办法:
在js中增加: //重新渲染前端
$(’#province_code’).selectpicker(‘refresh’);
<script>
$(function () {
$.ajax({
type: "post",
url: "/stock/getProvince",
success: function (data) {
for (var i = 0; i < data.length; i++) {
$('#province_code').append("<option value='" + data[i].id + "' >" + data[i].id + '-' + data[i].name + "</option>");
//重新渲染前端
$('#province_code').selectpicker('refresh');
}
},
error: function () {
alert("加载省失败");
}
});
});
</script>