I develop web application, using html, javascript (include knockout, jquery).
I'm still a little new at knockout.
I need ko-computed field, that relative to data-value property of checkboxes. But I have no idea how to do it.
Code sample:
<input type="checkbox" name="action" data-value="A"/>
<label>save</label>
<input type="checkbox" name="action" data-value="B" />
<label>export</label>
<input type="checkbox" name="action" data-value="C" />
<label>print</label>
I need property that will hand comma-string of data-value only of checked checkbox.
For example, if the first combo and the third combo are checked - I need the ko-computed field to have value: 'A,C'.
Is it possible? How?
Thanks.
No need for a computed
, a simple observableArray
will do as well:
HTML:
<input value="A" type="checkbox" name="action" data-bind="checked: CheckedActions"/>
<label>save</label>
<input value="B" type="checkbox" name="action" data-bind="checked: CheckedActions"/>
<label>export</label>
<input value="C" type="checkbox" name="action" data-bind="checked: CheckedActions"/>
<label>print</label>
JavaScript:
function VM() {
this.CheckedActions = ko.observableArray();
};
ko.applyBindings(new VM());
See Fiddle
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments