knockout.js - Update checkbox in KO Array -
can explain why following code not working. i'm trying toggle value when user clicks check box, state of checkbox never changes.
when console out values can see original value of val() -- toggle value, , can see new value -- yet checkbox doesn't update, appears locked.
there multiple checkboxes on form.
self.val = ko.observable(); self.updatecheckboxval = function () { return my.update.updatecheckboxval({ "id": self.logpropid(), "checkval": self.val() }); };
my html code:
<input data-bind="checked:val,click:function(){ updatecheckboxval() }" type="checkbox" />
the code should need bind checked state value in javascript is:
function myviewmodel() { self.val = ko.observable(); self.val.subscribe(function(newvalue) { // update database }); } ko.applybindings(new myviewmodel());
and html should like:
<input type="checkbox" data-bind="checked: val" />
edit:
added code subscribing can update database. here knockout documentation on subscribing: http://knockoutjs.com/documentation/observables.html#explicitly-subscribing-to-observables
Comments
Post a Comment