function MyViewModel() {
var self = this;
this.firstName = ko.observable('Planet');
this.lastName = ko.observable('Earth');
this.computedState = ko.observable(false);
this.fullName = ko.computed({
read: function () {
console.log("READ");
return this.firstName() + " " + this.lastName();
},
write: function (value) {
console.log("WRITE");
var lastSpacePos = value.lastIndexOf(" ");
if (lastSpacePos > 0) { // Ignore values with no space character
this.firstName(value.substring(0, lastSpacePos)); // Update "firstName"
this.lastName(value.substring(lastSpacePos + 1)); // Update "lastName"
}
},
owner: this,
disposeWhen : function(){ return self.computedState(); }
});
}
ko.applyBindings(new MyViewModel());
計算されたオブザーバブルは、破棄しても書き込みをトリガーします。それは正しい動作ですか?理由がわかりません。 JSFIDDLE の例