Getting Checkbox Value From Json Object
I am currently learning and playing around with the use of the knockout js framework. I have a basic set of fields for contacts. I am able to add contacts without any problems. But
Solution 1:
To enable a checkbox in knockout.js, the correct syntax is
Declare checkbox in HTML as
<inputtype='checkbox' data-bind="checked: bindName" />
To Enable/Disable checkbox through knockout.js
<scripttype="text/javascript">var viewModel = {
bindName : ko.observable(false),
};
</script>
Change the javascript code to
ko.utils.arrayForEach(contacts,function(contact) {
self.contacts.push({
firstName:contact.firstName,
lastName:contact.lastName,
phone:contact.phone,
alt_phone:contact.alt_phone,
male:ko.observable(contact.male), /*LineModified*/female:ko.observable(contact.female)/*LineModified*/
});
In HTML Change the code for checkbox
Male <inputtype="checkbox" data-bind='checked: male' />
Female <inputtype="checkbox" data-bind='checked: female' />
JS Fiddle Link - http://jsfiddle.net/dLbY7/15/
Post a Comment for "Getting Checkbox Value From Json Object"