Mebourne
Mebourne

Reputation: 225

Knockout.js attr error when combining string literal and object value

Working a new project using Knockout, the base documentation didn't seem to explain a case as below. Using the below attr calling; An incorrect href is produced: "api/degrees/function c(){if(0"

<a data-bind="attr: { href: '/api/degrees/' + fieldId }">

Although the following produces the fieldId value correctly

<a data-bind="attr: { href: fieldId }">

Is the only way to successfully combine the base url string and JS object value to use a Knockout computed value?

Thanks in advance for the help.

Upvotes: 14

Views: 5036

Answers (1)

Alan
Alan

Reputation: 46893

Try:

<a data-bind="attr: { href: '/api/degrees/' + fieldId() }">

Upvotes: 18

Related Questions