繁体   English   中英

引导选择DropDownList不显示

[英]Bootstrap-select DropDownList not showing

我有一个引导选择组合框,我在ajax调用Html中填充了数据

<div class="row">
<select id="selectGemeente1" class="selectpicker" data-live-search="true"></select>
</div>

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

我已经看到很多解决方案说应该将其放入$(document).ready

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

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

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

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

<script src="~/Scripts/jquery-2.2.3.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/i18n/defaults-nl_NL.min.js"></script>
<script src="~/Scripts/myCharts/gemeenteLijstLaden.js"></script>

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM