Knockout Js Passing Correct Parameter To Method
when using the click bind in knockout, how does knockout know to pass the correct parameter to the method its bound to?
Solution 1:
When calling your handler, Knockout will supply the current model value as the first parameter. This is particularly useful if you’re rendering some UI for each item in a collection, and you need to know which item’s UI was clicked.
from the documentation
There also is some discussion in the docs about how to pass more parameters by adding a wrapping function
<buttondata-bind="click: function(data, event) {
myFunction('param1', 'param2', data, event)
}">
Click me
</button>
Solution 2:
knockout understands which value to pass from context. it's the current model object. e.g if you're in a foreach knockout passes the current item.
Post a Comment for "Knockout Js Passing Correct Parameter To Method"