简体   繁体   English

使用自定义的基因敲除js选择绑定以及标准选择绑定

[英]Using custom knockoutjs select binding with standard select bindings as well

I am trying to combine custom knockoutjs binding with a standard binding. 我正在尝试将自定义的基因敲除结合与标准结合。 Although I have been able to find a related solution 虽然我已经能够找到相关的解决方案

ko.bindingHandlers.parentAreaComboBox = {

initialised: false,
init: function (element, valueAccessor, allBindingsAccessor, viewModel, context) {

    viewModel.parentAreas.subscribe(function (newParentAreas) {

        if (newParentAreas && newParentAreas.length > 0) {

            if (ko.bindingHandlers.parentAreaComboBox.initialised) {
                return;
            }
            ko.applyBindingsToNode(element, {
                options: viewModel.parentAreas,
                optionsCaption: 'Choose...',
                optionsText: 'Label',
                value: viewModel.selectedParentArea
            });
            $(element).chosen({});
            ko.bindingHandlers.parentAreaComboBox.initialised = true;
        }
    });
  }
};

but I am not able to make it work on mine . 但我无法使其在我的机器上工作。 What am I doing wrong here? 我在这里做错了什么?

Use the debugging console in your browser (press F12) and also the JSHint button in JSFiddle. 使用浏览器中的调试控制台(按F12),以及JSFiddle中的JSHint按钮。 Your VM constructor function is invalid. 您的VM构造函数无效。 Once you fix that, you'll notice that you're trying to use subscribe on something that is not an observable. 修复此问题后,您会发现您尝试对不可观察的内容使用subscribe

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

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