添加以下自定义绑定处理程序似乎打破了手风琴,这是由于淘汰赛的版本?
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);
}
}
答案 0 :(得分:1)
更新到knockout 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);
}
}