How to create a text link in javascript table for knockout?

I have some KnockoutJS code - it gets pulled into a list and binds it to a table.

For tabular data displaying name , I would like it to be <a href=...> , but not sure how to do it. The name is still displayed, by the way. But you can click on it.

here is my current code: -

 <tbody data-bind="foreach: items"> <tr> <td data-bind="text: name()"></td> <td data-bind="text: price()"></td> <td data-bind="text: endsOn()"></td> </tr> </tbody> 

nothing crazy.

I have another property called url that contains the full URL http://blah to direct users. In addition, I would like to open a new tab, please.

Any suggestions?

+7
source share
1 answer

You need to remove the data binding attribute from the td tag and put a with the attr binding inside td :

 <tbody data-bind="foreach: items"> <tr> <td><a data-bind="text: name, attr: {href: url}" target="_new"></a></td> <td data-bind="text: price"></td> <td data-bind="text: endsOn"></td> </tr> </tbody> 

PS You do not need to insert () after the property name in the data binding attribute unless you create an expression.

+17
source

All Articles