Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

knockout.js

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.

like image 445
Mebourne Avatar asked Oct 22 '12 00:10

Mebourne


1 Answers

Try:

<a data-bind="attr: { href: '/api/degrees/' + fieldId() }">
like image 161
Alan Avatar answered Nov 02 '22 18:11

Alan