必要なのはclick
バインディングです:
<input type="checkbox" data-bind="click: someFunction" />
そしてあなたのビューモデルで:
var ViewModel = function(data, event) {
this.someFunction = function() {
console.log(event.target.checked); // log out the current state
console.log("1");
return true; // to trigger the browser default behavior
}
};
JSFiddle のデモ。
または、checked
バインディングを使用する場合は、プロパティの変更イベントでサブスクライブできます。
<input type="checkbox" data-bind="checked: isChecked" />
そしてあなたのビューモデルで:
var ViewModel = function() {
this.isChecked = ko.observable();
this.isChecked.subscribe(function(newValue){
this.someFunction(newValue);
}, this);
this.someFunction = function(value) {
console.log(value); // log out the current state
console.log("1");
}
};
JSFiddle のデモ。