Note that there are some explanatory texts on larger screens.

plurals
  1. POKnockout binding works in text attribute but throws undefined error when used in href
    text
    copied!<p>I have the following binding within a <strong><a href="http://knockoutjs.com/documentation/foreach-binding.html" rel="nofollow"><code>foreach</code></a></strong> binding:</p> <pre><code>&lt;h5&gt;Id: &lt;span data-bind="text: ($root.link + id)"/&gt;&lt;/h5&gt; </code></pre> <p>and it displays fine.<br> If I change it out for </p> <pre><code>&lt;a data-bind="attr: { href: $root.link}"/&gt; </code></pre> <p>the anchor navigates fine (except obviously the <code>id</code> isn't appended to the end).<br> If I add in the <code>id</code></p> <pre><code>&lt;a data-bind="attr: { href: $root.link +id}"/&gt; </code></pre> <p>I get 'Unable to parse binding ... id is undefined'.</p> <p>Why does the exact same binding syntax work with text but not the attr binding?</p> <p>Thanks for your help.</p> <p>Update: I am using <a href="http://www.breezejs.com/" rel="nofollow">Breezejs</a> which uses the metadata to create the <strong><a href="http://knockoutjs.com/documentation/observableArrays.html" rel="nofollow"><code>observableArray</code></a></strong>. I've have done more testing and discovered that the binding fails when the field is of type <code>integer</code>. I passed in the name field and the binding works fine. I also tried <code>Id.toString()</code> but still get the Id undefined error. As suggested below, I am considering using a computed to solve the problem. If this is the only solution, I think it would be better to extend the breeze entity so it flows through to any downstream view model.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload