I am using the Play Framework and transitioning to use Knockout 2.0 which has thus far been awesome. One thing that I wanted to change was how I handle links. Presently I was storing the ID in a data attribute and using jQuery live-binding to create click handlers which would redirect to the appropriate URL substituting in the ID.
The Play Framework generates pure javascript functions from your routes file which construct links based on a series of parameters.
var searchAction = #{jsAction @Search.index(':query') /}
In the code you can then call searchAction({query: 'whatever'}) to get the appropriate URL.
What I'd like to figure out is a way to bind to these automatically generated functions without adding a ko.computed to the array item model. That is, I only define a ko.observableArray([]) in my model and then set it to an array returned from AJAX. I'd like to not have to explicitly define a model for these items.
Is there any way for me to perform this binding?
Here's a demo of what I want:
http://jsfiddle.net/gQspX/1/. The
/some/url/??? is what I would like replaced with a call to the
searchAction method with the corresponding ID. I would prefer to retain assigning the
href attribute to allow for middle-clicking to open in new tabs.