Knockout.js observable notify 'always' and subscribe -
i have following code:
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/
i wondering why agechangecount wont increment when old age , new age same (when input looses focus)?
because value
binding-handler ignoring model updating when new value matches old value. hence, subscriptions wouldn't run well.
see source
Comments
Post a Comment