I am trying to learn knockOut.js and can’t really get off the ground. When I call ko.applyBindings, my model is always undefined.
I’ve tried the solution already answered here.
I have also tried in jsFiddle: here
I have the following htm form:
<head>
<title>Mashup</title>
<script src="Scripts/jquery-1.8.2.js" type="text/javascript"></script>
<script src="Scripts/knockout-2.2.0.js" type="text/javascript"></script>
</head>
//html body
<script type="text/javascript">
$(window).load(function () {
function AppViewModel() {
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
}
var model = ko.applyBindings(new AppViewModel());
alert(model);
});
I’ve also tried using document ready:
//I've also tried document ready but still not working.
$(document).ready(function () {
function AppViewModel() {
this.firstName = ko.observable("Bert");
this.lastName = ko.observable("Bertington");
}
var model = ko.applyBindings(new AppViewModel());
alert(model);
});
I know ir will be something really stupid. Can anyone help please?
You do make two mistakes:
ko.applyBindings() does not return the model.
In your fiddle, you’re trying to use the “value” binding on a
<label>element. Such elements have no “value” property since you cannot enter anything. You need to use the “text” binding here:http://jsfiddle.net/4748N/8/