Click binding to parent function in foreach
Click binding to parent function in foreach
This method is used to remove the error :
This link will provide the details : http://jsfiddle.net/4cUv9/
For this use the result of the function as the click event because the parameter is a function reference.
The function call which is passed automatically include the data for that item so manual passing is not required :
<div data-bind="foreach: Contacts"> <a data-bind="click: $parent.Foo, text: Name">link</a> </div>
The details is provide in the click documentation.
The function reference is related to the click binding‘s parameter . So try to wrap the call into an anonymous function:
<div data-bind="foreach: Contacts"> <a data-bind="click: function() { $parent.Foo($data); }, text: Name">link</a> </div>
So , During pass the extra arguments into the click binding the user should wrap it to make a function.
The working of <button data-bind=”click: AddContacts”> expression is due to the user straightly referencing the AddContacts function there.