Javascript 使用Kendo UI MVVM的编程事件绑定不起作用

Javascript 使用Kendo UI MVVM的编程事件绑定不起作用,javascript,mvvm,event-handling,kendo-ui,event-binding,Javascript,Mvvm,Event Handling,Kendo Ui,Event Binding,我试图以编程方式将事件绑定到字段。“数据绑定>事件>更改”属性正被添加到DOM元素中。例如,这是我的脚本生成的HTML: <select id="MainContent_DetailsContent_TypeOfLoss" class="valid" name="TypeOfLoss" data-role="dropdownlist" data-text-field="text" data-value-field="value" data-bind="source: TypeOfLoss,

我试图以编程方式将事件绑定到字段。“数据绑定>事件>更改”属性正被添加到DOM元素中。例如,这是我的脚本生成的HTML:

<select id="MainContent_DetailsContent_TypeOfLoss" class="valid" name="TypeOfLoss" data-role="dropdownlist" data-text-field="text" data-value-field="value" data-bind="source: TypeOfLoss, events: { change: TypeOfLoss_updateSourceUsingValue }" style="display: none;">

建议您的主管不要选择这样的技术。文档一文不值(只是基本概述),它有我一生中见过的最糟糕的错误处理+支持真的很糟糕。。。
KendoDOMBinder: function (viewModel) {
    var binder = Object.create({
        _viewModel: {},
        _widgets: {},
        _root: {},

        init: function (viewModel) {
            this._viewModel = viewModel || Object.create(kendo.observable());
            this._widgets = App.Config.Widgets.defaults();

            return this;
        },
        bindField: function (node, bindings) {
            var that = this,
                val = [],
                ds,
                events = [],
                event,
                target,
                fnCallback,
                callback;

            // Empty data attributes will crash Kendo
            if (App.Utilities.isEmpty(bindings) === false) {
                // TODO: Should be using strategy pattern to process data attributes
                $.each(bindings, function (type, binding) {
                    switch (type) {
                        case 'source':
                            ds = App.Data.DataSource.Factory(binding)
                            val.push(type + ': ' + node.name);
                            that._viewModel.set(node.name, ds);
                            break;
                        case 'value':
                            // Make sure the property doesn't exist before adding it
                            if (that._viewModel.hasOwnProperty(binding) === false) {
                                // Add the property
                                that._viewModel.set(binding, '');
                                // TODO: accept function
                            }
                            break;
                        case 'events':
                            break;
                        case 'field':
                            event = binding.event || 'change';
                            type = binding.type;
                            target = binding.target;

                            if (binding.type == 'triggerUpdate') {
                                fnCallback = [node.name, binding.callback].join('_');
                                //console.log(fnCallback);

                                // Make sure the property doesn't exist before adding it
                                if (that._viewModel.hasOwnProperty(fnCallback) === false) {
                                    // Define the callback
                                    switch (binding.callback) {
                                        case 'updateSourceUsingValue':
                                            // Add the property
                                            fnCallback = that._viewModel.set(fnCallback, function () {
                                                alert("Doing something");
                                            });
                                            //console.log(that._viewModel);

                                            events.push(event + ': ' + fnCallback);
                                            break;
                                        case 'updateUsingValue':
                                            break;
                                    }
                                }
                            }

                            break;
                        default:
                            val.push(type + ': ' + binding);
                            break;
                    }
                });

                if (events.length > 0) {
                    val.push('events: { ' + events.join(', ') + ' }');
                }
            }
            console.log(val.join(', '));
            node.setAttribute('data-bind', val.join(', '));

            return this;
        },
        unbindField: function (key) {
            //this._viewModel.unbind;

            return this;
        },
        bind: function (selector) {
            selector = selector || 'body';

            kendo.bind($(selector), this._viewModel);
        },
        createFunction: function (ns, fn) {
            var nsArray = ns.split(/\./),
                currentNode = this._root,
                newNS;

           while (nsArray.length > 1) {
              newNS = nsArray.shift();

              if (typeof currentNode[newNS] === "undefined") {
                 currentNode[newNS] = {};
              }

              currentNode = currentNode[newNS];
           }

           if (fn) {
              currentNode[nsArray.shift()] = fn;
           } else {
              currentNode[nsArray.shift()] = {};
           }
        }
    });

    return binder.init(viewModel);
}