ko.computed field for data-value

user5260143

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.

haim770

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I map a field computed using ko.viewmodel

From Dev

ko computed not showing in view

From Dev

ko.Computed() is not updating with observableArray

From Dev

KO updatable computed from array

From Dev

KO Computed recalculating but not updating UI

From Dev

Cannot write a value to a ko.computed unless you specify a 'write' option

From Dev

Knockout JS Error: Cannot write a value to a ko.computed unless you specify a 'write' option

From Dev

read data value from computed property

From Dev

Changing A ko.observable into a ko.computed and vise versa

From Dev

Knockout - ko.computed with ko.isObservable and peek()

From Dev

Knockout - Difference between ko.computed and ko.observable.subscribe

From Dev

Django-model: Save computed value in a model field

From Dev

Lotus Notes: align entry value into a computed numeric field

From Dev

Passing values to KO computed observable within an object

From Dev

How to extract part of knockoutArray with ko.computed

From Dev

Make a factory function for creating ko.computed

From Dev

How to extract part of knockoutArray with ko.computed

From Dev

Make a factory function for creating ko.computed

From Dev

Access local function inside ko.computed

From Dev

How to make a ko.computed trigger

From Dev

KnockoutJS Mapping ko.computed Array into observableArray

From Dev

ko.computed property to determine visibility not working

From Dev

Ember-data model computed value, return value instead of promise

From Dev

KO Grid - repeating value

From Dev

Error: Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters

From Dev

Spring Data MongoDB Aggregation framework, exception accessing computed value in group

From Dev

KnockoutJs computed not working with last computed field

From Dev

How to get a ko.computed to work on observables inside an object

From Dev

Typescript class inheritance: override ko.computed method

Related Related

  1. 1

    How can I map a field computed using ko.viewmodel

  2. 2

    ko computed not showing in view

  3. 3

    ko.Computed() is not updating with observableArray

  4. 4

    KO updatable computed from array

  5. 5

    KO Computed recalculating but not updating UI

  6. 6

    Cannot write a value to a ko.computed unless you specify a 'write' option

  7. 7

    Knockout JS Error: Cannot write a value to a ko.computed unless you specify a 'write' option

  8. 8

    read data value from computed property

  9. 9

    Changing A ko.observable into a ko.computed and vise versa

  10. 10

    Knockout - ko.computed with ko.isObservable and peek()

  11. 11

    Knockout - Difference between ko.computed and ko.observable.subscribe

  12. 12

    Django-model: Save computed value in a model field

  13. 13

    Lotus Notes: align entry value into a computed numeric field

  14. 14

    Passing values to KO computed observable within an object

  15. 15

    How to extract part of knockoutArray with ko.computed

  16. 16

    Make a factory function for creating ko.computed

  17. 17

    How to extract part of knockoutArray with ko.computed

  18. 18

    Make a factory function for creating ko.computed

  19. 19

    Access local function inside ko.computed

  20. 20

    How to make a ko.computed trigger

  21. 21

    KnockoutJS Mapping ko.computed Array into observableArray

  22. 22

    ko.computed property to determine visibility not working

  23. 23

    Ember-data model computed value, return value instead of promise

  24. 24

    KO Grid - repeating value

  25. 25

    Error: Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters

  26. 26

    Spring Data MongoDB Aggregation framework, exception accessing computed value in group

  27. 27

    KnockoutJs computed not working with last computed field

  28. 28

    How to get a ko.computed to work on observables inside an object

  29. 29

    Typescript class inheritance: override ko.computed method

HotTag

Archive