我有以下代码:
HTML:
<p>Age:
<input data-bind="value:age" />
</p>
<p>Age has been changed: <span data-bind="text:ageChangeCount"></span> times</p>
JS:
function viewModel() {
var self = this;
self.age = ko.observable(10).extend({
notify: 'always'
}),
self.ageChangeCount = ko.observable(0),
self.age.subscribe(function (val) {
console.log('Someone has changed age');
self.ageChangeCount(self.ageChangeCount() + 1);
});
};
ko.applyBindings(new viewModel());
JSFiddle:http://jsfiddle.net/EstSiim/9majtx0h/
我想知道为什么ageChangeCount在老年和新年龄相同时(输入失去焦点时)不会增加?