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
<input type='checkbox' data-bind="checked: bindName" />
To Enable/Disable checkbox through knockout.js
<script type="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), /* Line Modified */
female: ko.observable(contact.female) /* Line Modified */
});
In HTML Change the code for checkbox
Male <input type="checkbox" data-bind='checked: male' />
Female <input type="checkbox" data-bind='checked: female' />
JS Fiddle Link - http://jsfiddle.net/dLbY7/15/
Post a Comment for "Getting Checkbox Value From Json Object"