I have a really simple question, but can’t understand what I am missing.
Here is the code:
$(document).ready(function() {
var viewModel = {
test: ko.observable(null)
}
var obj = {
name: "name123"
}
viewModel.test(obj);
ko.applyBindings(viewModel.test, document.getElementById("a"));
alert(viewModel.test.name());
});
link to jsfiddle: http://jsfiddle.net/bwkAB/
Why I can’t get the name property value?
UPDATE:
It should be
viewModel.test().name
Here is the corrected jsfiddle, You need to make the child objects property observable in order to bind to it. As well as adding the with binding to help with scope in the HTML