Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate Strings in Knockout

Tags:

knockout.js

I need to concatenate a url parameter onto an anchor tag. How would I go about insert it into the following template?

        <tbody data-bind="foreach: Customers">
            <tr class="rowEven">
                <td data-bind="text: Name"></td>
                <td data-bind="text: CustomerType"></td>
                <td><a href="customers.aspx?customer=[CustomerAccountIDHere]">Manage</a><a href="#">Guest Admin</a></td>
            </tr>
        </tbody>

I tried this will no luck:

            <tr class="rowEven">
                <td data-bind="text: Name"></td>
                <td data-bind="text: CustomerType"></td>
                <td><a data-bind="attr: { href: 'customers.aspx?customer=' + CustomerAccount_BID}">Manage</a><a href="#">Guest Admin</a></td>
            </tr>
like image 533
Darthg8r Avatar asked Aug 17 '12 21:08

Darthg8r


2 Answers

Add "()" - CustomerAccount_BID() works for me.

like image 137
Elaine Avatar answered Sep 19 '22 13:09

Elaine


I think the viewmodel might be the issue, here's a working example: http://jsfiddle.net/L4hUq

like image 25
kendaleiv Avatar answered Sep 21 '22 13:09

kendaleiv