knockout.js - Simple Knockout Viewmodel Issue -
i have simple knockout viewmodel problem, driving me round in circles... siteid property binds first time, doesn't update on click:
anyone see what's wrong this?
function newsiteaccessviewmodel() { var self = this; self.siteid = ko.observable(); } $(document).ready(function () { var newsiteaccessviewmodel = new newsiteaccessviewmodel(); newsiteaccessviewmodel.siteid = 'none yet'; ko.applybindings(newsiteaccessviewmodel); $(".testclick").click(function() { newsiteaccessviewmodel.siteid = "a new one"; alert(newsiteaccessviewmodel.siteid); }); });
html:
<h3 data-bind="text:siteid" ></h3>
so result changes value "none yet", doesn't subsequently update on click. alert shows new value...
you set value of observable invoking observable function. wrote:
newsiteaccessviewmodel.siteid = 'none yet';
you want
newsiteaccessviewmodel.siteid('none yet');
and within click handler.
knockout.js
No comments:
Post a Comment