Maybe optionValue was not the right comparison. But here is the example provided in the documentation for checkedValue. To me it's saying you should use checkedValue property if you want the value to be something other than a string (an object, possibly) and that the code example would add the item object to $root.chosenItems, not just the itemName property value of "Choice 1'. I assume you would have to iterate through $root.chosenItems and do something like $data.itemName to get the itemName of each checked item...
checkedValue
If your binding also includes checkedValue, this defines the value used by the checked binding instead of the element’s value attribute. This is useful if you want the value to be something other than a string (such as an integer or object), or you want the value set dynamically.
In the following example, the item objects themselves (not their itemName strings) will be included in the chosenItems array when their corresponding checkboxes are checked:
<!-- ko foreach: items --> <input type="checkbox" data-bind="checkedValue: $data, checked: $root.chosenItems" /> <span data-bind="text: itemName"></span><!-- /ko --><script type="text/javascript"> var viewModel = { items: ko.observableArray([ { itemName: 'Choice 1' }, { itemName: 'Choice 2' } ]), chosenItems: ko.observableArray() };</script> |
<div data-bind="foreach: AdHocReport.AcademicLevels()">
<div><input type="checkbox" data-bind="attr: {value: Value}, checkedValue: $data, enable: !$root.AdHocReport.AllAcademicLevels(), checked: $root.SelectedAcademicLevels"/><span data-bind=" text: Display"></span></div>
</div>