1

添加以下自定义绑定处理程序似乎打破了手风琴,这是由于淘汰赛的版本吗?

ko.bindingHandlers.accordion = {
init: function(element, valueAccessor) {
    var options = valueAccessor() || {};
    setTimeout(function() {
        $(element).accordion(options);
    }, 0);

    //handle disposal (if KO removes by the template binding)
      ko.utils.domNodeDisposal.addDisposeCallback(element, function(){
          $(element).accordion("destroy");
      });
},
update: function(element, valueAccessor) {
    var options = valueAccessor() || {};
    $(element).accordion("destroy").accordion(options);
}

}

4

1 回答 1

1

在更新到淘汰赛 2.2 之后,手风琴自定义绑定处理程序需要有对 updateOn 的引用,因此不会为手风琴上的每个事件调用过多的绑定。

   <ul data-bind="foreach: items, accordion:{updateOn: items}"></ul>

   ko.bindingHandlers.accordion = {
    init: function(element, valueAccessor) {
        var options = valueAccessor() || {};
        setTimeout(function() {
            $(element).accordion(options);
        }, 0);

        //handle disposal (if KO removes by the template binding)
          ko.utils.domNodeDisposal.addDisposeCallback(element, function(){
              $(element).accordion("destroy");
          });
    },
    update: function(element, valueAccessor) {
        var options = valueAccessor() || {};
        if (options.updateOn && ko.isObservable(options.updateOn)) {
            options.updateOn();
        }
        $(element).accordion("destroy").accordion(options);
    }
}
于 2013-06-10T14:35:29.020 回答