I am trying to update the UI after chages to viewModel but it doesn't work , am I missing something ? http://jsfiddle.net/rdZjb/1/
viewModel = {
firstName : ko.observable("adrian")
}
$("#button1").click(
function ()
{
viewModel.firstName = "Paul";
alert(viewModel.firstName);
}
)
ko.applyBindings(viewModel);
You are working with
observables
in wrong way. Eachobservable
is a function so when you setting or geting value you should use()
:Also it is bad practice to use jQuery click event. Use knockout
click
binding instead:Here is working fiddle: http://jsfiddle.net/vyshniakov/rdZjb/2/
To change an observable (after initializing it) via Javascript, you need to call it as a function such as