javascript - Knockout js checkbox list based on Dropdown list showing by default checked, it should be unchecked -
javascript - Knockout js checkbox list based on Dropdown list showing by default checked, it should be unchecked -
if changing dropdown value binding of checkbox list in knockout showing me default checked, want display unchecked..
on page load checkbox list working fine.. when dropdown / select value changed kid checkboxlist showing checked.. want display uncheck..
also after alter event of select box if check check checkbox - showing me boolean not function error //html
<p> <input type="checkbox" data-bind="checked: allselect" /> <table> <tbody data-bind="foreach: locations"> <td> <input type="checkbox" data-bind="checked: isselected"> </td> <td> <p data-bind="text: name"></p> </td> </tbody> </table> </p>
//checkbox all
var locations = model.locations; var location = function (location) { var self = this; self.id = location.id; self.name = location.name; self.isselected = ko.observable(location.isselected); console.debug("kp1 : " + location.isselected); }; var mappedlocations = []; ko.utils.arrayforeach(locations, function (location) { mappedlocations.push(new location(location)); }); console.debug(mappedlocations); self.locations = ko.observablearray(mappedlocations); self.allselect = ko.computed({ read: function () { var allselected = true; self.selectedids = []; ko.utils.arrayforeach(self.locations(), function (item) { console.debug("kp : " + item.isselected()); if (!item.isselected()) { allselected = false; } else { self.selectedids.push(item.id); } }); console.debug('selectedids: ' + self.selectedids); homecoming allselected; //to trigger browser default bahaviour }, write: function (value) { ko.utils.arrayforeach(self.locations(), function (item) { item.isselected(value); }); } });
//dropdown
self.changeproject = function () { console.debug('change project ' + self.modelingprojectid()); self.locations.removeall(); var info = { id: self.modelingprojectid() }; $.ajax({ type: "get", contenttype: "application/json", url: root + 'location/locationsbyprojectandparentid', data: info }).done(function (json, textstatus, jqxhr) { //see http://api.jquery.com/jquery.ajax/ (var = 0; < json.length; i++) { self.locations.push(new location(json[i])); } }); }
javascript jquery knockout.js
Comments
Post a Comment