I have a checkbox group generated dynamically and I need to bind it to my knockout viewmodel.
Here is my code for the checkbox group:
<p>
<label>Properties</label>
<span class="formwrapper">
@{
foreach (ComboProperty item in this.Model.Properties)
{
@:<input type="checkbox" name="chkproperty" value="@item.PropertyId" /> @item.Name<br/>
}
}
</span>
</p>
So here instead of a Radio Button group I can have multiple checkboxes selected. So first need to know how to create my knockout viewmodel in order to manage multiple values and then how to bind it.
I have created this in fiddler for reference. It has the json collection.
Thanks a lot.
I am not sure what you are trying to accomplish but I’ve updated your jsFiddle in order to make it work:
http://jsfiddle.net/SSHev/11/
When you have a multiple checkboxes that are related, you have a multiple choice input. In Knockout, such an input can be mapped to an array of values. As you see in my updated fiddle, checking and unchecking the boxes will insert or remove the appropriate value from the
self.propertiesvariable. This variable is an observable array.