【问题标题】:knockout kendo events fires twice淘汰赛剑道赛事开火两次
【发布时间】:2015-05-27 21:17:28
【问题描述】:

嘿,我的 knockout-kendo 框架有问题。
每个事件都会触发两次。

谁能告诉我我的代码有什么问题?

我创建了一个小的fiddle

var StoreViewModel = function () {
    var self = this;
    this.stores = ko.observableArray(stores);
    this.selectedStore = ko.observable(stores[0].Id);

    // this event fires twice, dont know why!
    this.dataBoundEvent = function () {
        alert('databound event ...');
        //doSomething();
    };
    this.changeEvent = function () {
        alert('change event ...');
        //doSomething();
    };
};

谢谢!

【问题讨论】:

    标签: javascript knockout.js kendo-ui


    【解决方案1】:

    在初始化网格和设置数据时调用绑定事件。

    要阻止这种情况,只需使用 dataSource 而不是 data

    <div id="wrapper">
        <select data-bind="kendoDropDownList: {
            dataSource: stores,
            dataTextField: 'Address',
            dataValueField: 'Id',
            dataBound: dataBoundEvent,
            change: changeEvent
        }"></select>
    </div>
    

    dataSource是kendo的正常方式和支持方式。

    【讨论】:

      【解决方案2】:

      我相信正在调用 dataBoundEvent

      1. 绑定后备数据(存储)
      2. 绑定选中的值(selectedStore)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-26
        • 2014-07-27
        • 1970-01-01
        • 1970-01-01
        • 2014-08-27
        相关资源
        最近更新 更多