mailto link binding?

692 views
Skip to first unread message

thn...@gmail.com

unread,
Jun 13, 2012, 5:55:48 PM6/13/12
to knock...@googlegroups.com
I'm new to Knockout and trying to determine how I might generate an email link with knockout. The problem is around using "href:" with "mailto:". I've tried various variants including the below and others but either it won't get rendered as mailto link, the property name will be sent instead of the value, or nothing will be rendered. Tips on what syntax I should be using for this? Thanks

<a data-bind="mailto: EmailAddress, text: EmailAddress"></a>
<a data-bind="attr: { href: 'mailto:PrimaryEmail', title: PrimaryEmail }, text : PrimaryEmail">

rpn

unread,
Jun 13, 2012, 11:00:54 PM6/13/12
to knock...@googlegroups.com
Hello-
You would want to do it like: 

<a data-bind="attr: { href: 'mailto:' + PrimaryEmail, title: PrimaryEmail }, text : PrimaryEmail">

if PrimaryEmail is an observable, then it would look like:

<a data-bind="attr: { href: 'mailto:' + PrimaryEmail(), title: PrimaryEmail }, text : PrimaryEmail">

geoff.eve...@gmail.com

unread,
Jun 14, 2012, 11:15:58 AM6/14/12
to knock...@googlegroups.com
Thank you, that worked great. I find it a bit verbose though and created an HTML helper for it. Speaking of, has anyone created any knockout html helpers? I guess the use of such could be debated in terms of pros and cons but...
Reply all
Reply to author
Forward
0 new messages