Q:

Simple Knockout.JS Data Binding

I just want to pass in a parameter to a function like this:
<button data-bind="click: myFunction( text: surveyId )"></button>

function myFunction(param) {

  alert(p);

}

So, I just want to pass in a parameter to a function that is part of my knockout model.  I want this function to reside outside of the knockout code.
Very, very basic stuff here. Can anyone help me out?

A:

If you need to pass a parameter in like this, you can use an anonymous function, like this:
<button data-bind="click: function(){ myFunction(surveyId); }"</button>

function myFunction(param) {
  alert(param);
}

If the view model property is an observable, you'll need to account for that - either by retrieving the value directly in the binding:
<button data-bind="click: function(){ myFunction(surveyId()); }"</button>

or unwrapping it as part of the external function:
function myFunction(param) {
  alert(ko.utils.unwrapObservable(param));
}

