Search code examples
jqueryknockout.jsjquery-templates

knockout.js not working with jquery template property


I am not sure what is going on but I want to pass the "Route" property to my function in a jquery template, but it always comes through as an array with $index, $data, and $Route says it can't be found. The only way I got it to work was with the below template. I would rather do it this way <a href="" data-bind="attr: { href: app.viewModel.members.createRoute($Route) }">${Title}</a>.

I am using the jquery 1.3 beta, and jquery template 1.0.0pre.

<script id="actionsTemplate" type="text/html">
    {{each $data}}
    {{if $index == 0}}
        <li style="float: left">
            <h1 data-bind="html: app.viewModel.members.page.title"></h1>
        </li>
    {{/if}}

    <li>
        <a href="" data-bind="attr: { href: app.viewModel.members.createRoute($data[$index].Route) }">${Title}</a>
    </li>
    {{/each}}
</script>

Solution

  • Looks like you want to use Route (so not $Route) or $data.Route (same thing).