简体   繁体   English

Bootstrap multiselect下拉列表.val()不更新

[英]Bootstrap multiselect dropdown .val() not updating

I have 3 drop downs which are cascading. 我有3个下降级联。 Zone -- > Region --> Territory 区域 - >区域 - >区域

I am using Bootstrap multiselect drop downs. 我正在使用Bootstrap multiselect下拉菜单。

When i select the Zone drop down the respective regions are to be bound and simultaneously the newly bound regions' territories are to be bound to the territory drop down. 当我选择区域下拉时,各个区域将被绑定,同时新绑定区域的区域将被绑定到区域下拉。

Here is my drop-down initialisation code. 这是我的下拉初始化代码。

$('#ddlZone').multiselect({
            enableClickableOptGroups: true,
            enableCollapsibleOptGroups: true,
            enableFiltering: true,
            includeSelectAllOption: true,
            nonSelectedText: 'Select Zone',
            enableCaseInsensitiveFiltering: true,
            selectAllNumber: true,
            onChange: function(option, checked,select) {
                FillRegionsDropdown();
                FillTerritoriesDropdown();

            }

Here is the code for the above functions. 以下是上述功能的代码。

function FillRegionsDropdown()
    {


        var Zone=$('#ddlZone').val();
        if(Zone != null)
        {
            Zone= Zone.join(",");
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "@Url.Action("BindRegionsOnZonesAjax", "GeoMap")",
                data: "{ZoneIds:'" + Zone + "'}",

                success: function (Result)
                {


                    $("#ddlRegion").html("");

                    $('#ddlRegion').multiselect( 'refresh' );
                    $.each(Result, function (key, value) {
                        $("#ddlRegion").append($("<option></option>").val(value.Value).html(value.Text));
                    });
                    $('#ddlRegion').multiselect( 'rebuild' );
                    $("#ddlRegion").multiselect('selectAll', false);
                    $("#ddlRegion").multiselect('updateButtonText');

                }


        });

    }
}

The above code works perfectly ie on Zone dropdowns change the regions get bound and set to select all. 上面的代码工作正常,即在区域下拉列表中更改区域绑定并设置为全部选择。

But the issue is with Binding territory drop down with zone drop down change. 但问题是绑定区域下降与区域下拉变化。

And here is the code for Territory dropdowns binding. 以下是Territory下拉列表绑定的代码。

 function FillTerritoriesDropdown()
    {

        var rgns=$('#ddlRegion').val();
        if(rgns != null)
        {
            rgns= rgns.join(",");
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "@Url.Action("BindTerritoriesOnRegionsAjax", "GeoMap")",
                data: "{RegionIds:'" + rgns + "'}",

            success: function (Result)
            {


                $("#ddlTerritory").html("");

                $('#ddlTerritory').multiselect( 'refresh' );
                $.each(Result, function (key, value) {
                    $("#ddlTerritory").append($("<option></option>").val(value.Value).html(value.Text));
                });
                $('#ddlTerritory').multiselect( 'rebuild' );
                $("#ddlTerritory").multiselect('selectAll', false);
                $("#ddlTerritory").multiselect('updateButtonText');

            }


            });

    }
    }

Here the $('#ddlRegion').val() doesn't get updated to the newly bound region values which is caused due to zone drop down change. 这里$('#ddlRegion').val()不会更新到由于区域下拉更改而导致的新绑定区域值。

$('#ddlRegion').val() still contains the initial page load region values. $('#ddlRegion').val()仍然包含初始页面加载区域值。

I have been struck with this for more than 6 hours now. 我现在被震惊了6个多小时。

Can some one help me to fix this issue?, 有人可以帮我解决这个问题吗?

Try using async:false in both FillTerritoriesDropdown() and FillREgionsDropdown() functions. 尝试在FillTerritoriesDropdown()和FillREgionsDropdown()函数中使用async:false ie in the ajaxcalls to the controller of those 2 functions. 即在ajaxcalls到那两个函数的控制器。

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

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