Passing parameter using onclick or a click binding with KnockoutJS

BlaShadow picture BlaShadow · Apr 6, 2012 · Viewed 102.3k times · Source

I have this function:

function make(place)
{
  place.innerHTML = "somthing"
}

I used to do this with plain JavaScript and html:

<button onclick="make(this.parent)">click me</button>

How can I do this using idiomatic knockout.js?

Answer

Juliano Sales picture Juliano Sales · Feb 22, 2013

Use a binding, like in this example:

<a href="#new-search" data-bind="click:SearchManager.bind($data,'1')">
  Search Manager
</a>
var ViewModelStructure = function () {
    var self = this;
    this.SearchManager = function (search) {
        console.log(search);
    };
}();