Sunday, April 1, 2012

Trouble getting observableArray's running in Knockout?

I'm watching Knockout Fundamentals by Steve Michelotti

I was having trouble getting the example running that he wrote to show observableArray's.
There must be a bug in this URL
http://github.com/downloads/SteveSanderson/knockout/jquery.tmpl.js

If you load the libraries in this order:
http://code.jquery.com/jquery-1.7.1.min.js
http://github.com/downloads/SteveSanderson/knockout/jquery.tmpl.js
http://github.com/downloads/SteveSanderson/knockout/knockout-1.1.2.js

You will get all sorts of errors that will be very hard to track down.

Instead, use this URL from Microsoft and it works.
http://code.jquery.com/jquery-1.7.1.min.js
http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js
http://github.com/downloads/SteveSanderson/knockout/knockout-1.1.2.js

To get these working in jsFiddle, load jquery.tmpl.js first and knockout second. For jQuery you can choose the latest jquery framework from the frameworks dropdown.
The example working in jsfiddle

Here is the code outside of jsFiddle





Double click on these pictures to see the code enlarged.

1 comment:

Unknown said...

You are using an older version of KO. Using the 1.3beta version (today, 2.1 is the latest version) of the library (which was used in the Pluralsight course), you don't even need a reference to jQuery template library to do this. See here: http://jsfiddle.net/smichelotti/tyyDM/