我正在尝试创建多选择下拉动态。
HTML
<select id="impact-report-type-filter-input" name="impact-report-type-filter-input" multiple='multiple'>
的jQuery
$("#impact-report-type-filter-input").multiselect({
noneSelectedText: '',
minWidth: 165,
header: "Select Recipient(s)",
});
//in other function im trying this for options
var filterList = data.filterList; // ["1495cat", "Category Test","Labour", "New Law 1", "testing"]
//var filterString = filterList.toString();
//var dataArray = filterString.split(",");
//var data1="1,2,3,4";
//Make an array
//var dataarray=data1.split(",");
$("#impact-report-type-filter-input").val(dataarray);//filterList);
$("#impact-report-type-filter-input").multiselect("refresh");
但是我没有在下拉列表中获得任何选项,请参考图片
答案 0 :(得分:0)
尝试以下代码。包括bootstrap-multiselect.css也
$(document).ready(function() {
//in other function i'm trying this for options
$("#impact-report-type-filter-input").multiselect({
noneSelectedText: '',
minWidth: 165,
header: "Select Recipient(s)",
});
var filterList = ["1495cat", "Category Test","Labour", "New Law 1", "testing"]; //
for(f in filterList){
$('#impact-report-type-filter-input').append($('<option>', {
value: filterList[f],
text: filterList[f]
}));
}
$("#impact-report-type-filter-input").multiselect("refresh");
});