繁体   English   中英

敲除启用绑定不适用于kendocombobox

[英]Knockout enable binding doesn't work with kendocombobox

Html.Kendo().ComboBoxFor(m => m.CityId).HtmlAttribute("data-bind", "enable: IsCityEnabled")

组合框是一个复杂元素,由多个元素(输入,箭头按钮,保持值的不可见输入)组成,如下所示。上面的表达式在不可见的输入元素上添加了绑定表达式。

<span class="k-widget k-combobox k-header">
<span tabindex="-1" unselectable="on" class="k-dropdown-wrap k-state-default k-state-hover">
    <input name="BankId_input" class="k-input valid" type="text" autocomplete="off" maxlength="524288" role="combobox" aria-expanded="false" tabindex="0" aria-disabled="false" aria-readonly="false" aria-autocomplete="both" aria-owns="      BankId_listbox" aria-busy="false" aria-activedescendant="BankId_option_selected" aria-invalid="false" style="width: 100%;">
    <span tabindex="-1" unselectable="on" class="k-select">
        <span unselectable="on" class="k-icon k-i-arrow-s" role="button" tabindex="-1" aria-controls="BankId_listbox">select</span>
    </span>
</span>
<input data-val="true" data-val-number="The field Bank Combo must be a number." id="BankId" name="BankId" no-custom-input="true" data-bind="enable : IsCityReadOnly" type="text" data-role="combobox" aria-disabled="false" aria-readonly="false" style="display: none;" aria-invalid="false" aria-describedby="BankId-error" class="valid">

因此,更改模型只会影响不可见元素

我需要一个通用解决方案,而无需将订户添加到淘汰模型成员中。

解决方案

        var control = $("#" + ControlName).data("kendoComboBox");
        // configuration of the observer:
        var config = { attributes: true, childList: false, characterData: true };
        // create an observer instance
        var observer = new MutationObserver(function (mutations) {
            mutations.forEach(function (mutation) {
                if (mutation.type === "attributes") {
                    if (mutation.attributeName === "disabled") {
                        control.enable(!mutation.target.disabled);
                        observer.disconnect();
                        observer.observe(control.element[0], config);
                    }
                }
            });
        });
        // pass in the target node, as well as the observer options
        observer.observe(control.element[0], config);

暂无
暂无

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

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