【发布时间】:2015-01-31 11:53:13
【问题描述】:
所以,我想为我的复选框使用 iCheck,但这需要自定义绑定。 Kendo MVVM、knockout 或任何其他 js 库。
我的自定义绑定几乎完美无缺,但它不会在单击复选框时触发。如果我将输入从复选框更改为文本输入,则单击自定义绑定效果很好。
kendo.data.binders.myICheck = kendo.data.Binder.extend({
init: function (element, bindings, options) {
//call the base constructor
kendo.data.Binder.fn.init.call(this, element, bindings, options);
var that = this;
//listen for the change event of the element
$(that.element).on("click", function () {
that.click(); //call the change function
});
},
click: function () {
this.bindings["myICheck"].set(false);
},
refresh: function () {
var value = this.bindings["myICheck"].get();
if (value) {
$(this.element).iCheck('check');
} else {
$(this.element).iCheck('uncheck');
}
}
});
HTML 是
input indeterminate="false" data-bind="myICheck: rememberUserInfo" class="check">
【问题讨论】: