I have completed most of the tutorials and read the documentation and
am now attempting to experiment with a 'live' knockout.js application/
page.
To keep things simple, I've simply copied the Hello World example
(
http://knockoutjs.com/examples/helloWorld.html). I've got a main html
file that includes the examples HTML:
<script type='text/javascript' src='knockout-2.0.0.js'></script>
<script type='text/javascript' src='helper.js'></script>
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
<h2>Hello, <span data-bind="text: fullName"> </span>!</h2>
I then have a 'helper.js' file that contains the View Model code:
var ViewModel = function(first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
this.fullName = ko.computed(function() {
// Knockout tracks dependencies automatically. It knows that
fullName depends on firstName and lastName, because these get called
when evaluating fullName.
return this.firstName() + " " + this.lastName();
}, this);
};
ko.applyBindings(new ViewModel("Planet", "Earth")); // This makes
Knockout get to work
Unfortunately, I am still unable to get this to work. Looking at
firebug, I can see that the two .js files are visible to the browser.
I am stumped!
Thanks in advance.