I have a ViewModel that holds a subclass, and I want to be notified when one of the property in the subclass is modified, something like this:
var Person = function(){
this.name = ko.observable("john doe");
this.age = ko.observable(45);
};
var ViewModel = function() {
this.Owner = ko.observable(new Person());
this.Owner().subscribe(function(){
alert("Someone updated owner");
});
};
var vm = new ViewModel();
vm.Owner().age(34);
But the above code doesn’t work…
You can try this:
Here is working fiddle: http://jsfiddle.net/vyshniakov/hpKZj/
If you want to implement something like
isDirtyflag read the following article: http://www.knockmeout.net/2011/05/creating-smart-dirty-flag-in-knockoutjs.html