I have an observableArray
in my knockout application as shown below:
self.Parents = ko.observableArray([
{
Father: 'Father-A',
Mother: 'Mother-A',
Children: ko.observableArray([
{Name: 'Child-A1'},
{Name: 'Child-A2'},
{Name: 'Child-A3'}])
},
{
Father: 'Father-B',
Mother: 'Mother-B',
Children: ko.observableArray([
{Name: 'Child-B1'},
{Name: 'Child-B2'},
{Name: 'Child-B3'}])
}]);
And I have computed observable
on Parents
variable as shown below:
ko.computed(function(){
alert('Record Updated');
console.log(self.Parents());
});
Now when I add/remove Children to any of the Parent, I believe above computed function should be called as Parent variable is indirectly getting updated when I add/remove child. But it is not working. As a solution of below fiddle, Record Updated
alert should be displayed.
So how can I achieve this ?
Note: Here please take a note that this is just a sample I have created. In actual scenario, Parents object is passed to the third party grid library. And if any change occurs in Parent/Child that grid should be updated. That's the reason why I have written
self.Parents()
incomputed function
and notChildren