How to access $parent or $parents[] in knockout viewmodel click event?
knockout.js
Solution
Alternatively, you can pass parameters to your view model's event handler the following way: Change your `save` method
self.save = function(theParents) {
theParents[1].actionTaken();
}
and bind your handler the following way:
data-bind="click: function() { $data.save($parents) }"
For further information, please refer to Note 2 in the click handler's documentation (you need to scoll down a bit)
Problem
I've got a situation where I'd like to notify a grandparent or $parents[1] of a click event that occurs in a sub viewmodel. So basically I'd like to be able to do this ``` self.$parents[1].actionTaken ``` I think this doesn't work because of binding context vs viewModel but I'd like to hear if anyone has an ideas on the correct way to do something like this. Thanks ``` self.save = function () { //do stuff to self first, then self.$parents[1].actionTaken(); }; ```