Sunday, February 12, 2012

KnockoutJS calling methods with context in bindings


Here I have an example code:




<div data-bind="foreach: someData1">
<a href="#" data-bind="click: myFunction"></a>
</div>

<div data-bind="foreach: someData2">
<a href="#" data-bind="click: myFunction"></a>
</div>



How inside myFuncion code to know when it's called: when foreaching someData or someData2?

1 comment:

  1. You can access both the item and the click event in myFunction.

    viewModel.myFunction = function (item, event) {
    // event.target = <a>
    };


    You should check out the official Knockout documentation for the click binding.

    ReplyDelete