Bootstrap-select DropDownList未显示

我有一个bootstrap-selectcombobox,我在ajax调用Html中填充数据

Ajax调用:

 var gemeenteLijst = []; var GetGemeentes = function () { $.ajax({ type: "GET", dataType: "json", url: 'https://localhost::blabla', contentType: "application/json; charset=utf-8", success: function (data) { var test = document.getElementById("selectGemeente1"); data.forEach(function (item) { var opt = document.createElement("option"); opt.value = item.GemeenteId; opt.innerHTML = item.Naam; test.appendChild(opt); }); }, error: function (xhr, status, error) { alert(xhr.responseText); } }); } $(document).ready(function () { GetGemeentes(); }) 

运行我的应用程序后,我的选择已填满,但下拉列表未打开..

运行后的HTML

我已经看到很多解决方案,我应该把它放在我的$(文件).ready中

 $(".selectpicker").html(optgroup); 

但后来我得到一个错误,说.selectpicker不是一个函数。

 gemeenteLijstLaden.js:36 Uncaught TypeError: $(...).selectpicker is not a function 

我已经实现了这些脚本文件

      

我找到了解决方案。 我只需要刷新我的选择

 $('.selectpicker').selectpicker('refresh'); 
 success: function (data) { var selectGemeent = $("#selectGemeente1"); selectGemeent.empty(); $('#selectGemeente1').append($(""). attr("value", "0"). text("Select")); $.each(data.forEach, function (index, item) { selectGemeent.append($(' 

在你的ajax成功中使用它,并在文本和值之后添加你的其他文件