【问题标题】:Knockout enable binding doesn't work with kendocombobox淘汰赛启用绑定不适用于 kendocombobox
【发布时间】:2015-09-18 05:32:37
【问题描述】:
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">

所以对模型的改变只影响不可见的元素

我需要一个通用的解决方案,而不需要向淘汰模型成员添加订阅者。

【问题讨论】:

  • 设身处地为我们着想:我们非常不清楚您在问什么。请阅读this guidance 并编辑您的问题以澄清。

标签: javascript asp.net knockout.js kendo-ui


【解决方案1】:

解决办法

        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);

【讨论】:

    猜你喜欢
    • 2013-01-13
    • 2016-11-07
    • 2015-01-18
    • 1970-01-01
    • 1970-01-01
    • 2018-03-25
    • 2017-10-15
    • 1970-01-01
    • 2014-08-04
    相关资源
    最近更新 更多