Knockout Computed - write a new value

leaksterrr

I'm building a very number/options heavy application using Knockout and on the screen I'm currently working on is pretty complex in terms of what's happening behind the scenes. The whole screen is dynamic and the options displayed are generated from an observableArray.

The way the app works is pretty complex and I've created a slimmed down JSFiddle for you to view here: http://jsfiddle.net/z56zV/

Whenever the button is clicked, I want getValueOne to reset to 0 but no matter what I try, nothing seems to writing the value to getValueOne.

ps. I know you shouldn't really submit a SO post with no code but I feel the best way for you to udnerstand what exactly is going on behind the scenes is to play with the JSFiddle.

Update: I have the code working to an extent, where the write function of getValueOne is reading the value being sent to the computed but I'm having difficulty storing this as the new value? http://jsfiddle.net/z56zV/1/

Andy Clarke

The computed is calculating stuff for you - you can perform some action on the write, but it isn't in itself a variable you can write to.

To clear the computed, you'd have to clear the underlying data ...

self.resetValueToZero = function () {
    for (var i = 0; i < self.computedValues().length; i++) {
        self.computedValues()[0].value(0);
    }
};

Fiddle Demo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

knockout foreach computed value

From Dev

knockout foreach computed value

From Dev

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

From Dev

knockout.js observableArray computed value

From Dev

Knockout update computed value after blur

From Dev

Knockout computed observable is not updating value when changing its dependencies

From Dev

Put computed value inside progress bar Knockout js

From Dev

Knockout Computed with Parameter not updated

From Dev

Knockout writable computed observables

From Dev

Knockout Computed Observable with parameters

From Dev

Knockout computed property not binding

From Dev

knockout observable array computed

From Dev

Knockout writable computed observables

From Dev

Knockout computed property not binding

From Dev

observable and computed are not working properly Knockout

From Dev

Knockout custom binding to a computed column

From Dev

Knockout Js computed not working in a model

From Dev

Knockout js Computed not being fired

From Dev

Knockout computed observable with access to observableArray

From Dev

Knockout Modifying ObservableArray inside Computed

From Dev

Inheritance and overriding Knockout computed observable

From Dev

Knockout ViewModel computed garbage collection

From Dev

Subscribe arrayChange on knockout computed accessor

From Dev

Knockout ViewModel computed garbage collection

From Dev

Knockout js Computed not being fired

From Dev

Knockout Modifying ObservableArray inside Computed

From Dev

Inheritance and overriding Knockout computed observable

From Dev

Add computed value as new column while also removing duplicates

From Dev

Knockout Force notify subscribers of an observable when setting new value

Related Related

  1. 1

    knockout foreach computed value

  2. 2

    knockout foreach computed value

  3. 3

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

  4. 4

    knockout.js observableArray computed value

  5. 5

    Knockout update computed value after blur

  6. 6

    Knockout computed observable is not updating value when changing its dependencies

  7. 7

    Put computed value inside progress bar Knockout js

  8. 8

    Knockout Computed with Parameter not updated

  9. 9

    Knockout writable computed observables

  10. 10

    Knockout Computed Observable with parameters

  11. 11

    Knockout computed property not binding

  12. 12

    knockout observable array computed

  13. 13

    Knockout writable computed observables

  14. 14

    Knockout computed property not binding

  15. 15

    observable and computed are not working properly Knockout

  16. 16

    Knockout custom binding to a computed column

  17. 17

    Knockout Js computed not working in a model

  18. 18

    Knockout js Computed not being fired

  19. 19

    Knockout computed observable with access to observableArray

  20. 20

    Knockout Modifying ObservableArray inside Computed

  21. 21

    Inheritance and overriding Knockout computed observable

  22. 22

    Knockout ViewModel computed garbage collection

  23. 23

    Subscribe arrayChange on knockout computed accessor

  24. 24

    Knockout ViewModel computed garbage collection

  25. 25

    Knockout js Computed not being fired

  26. 26

    Knockout Modifying ObservableArray inside Computed

  27. 27

    Inheritance and overriding Knockout computed observable

  28. 28

    Add computed value as new column while also removing duplicates

  29. 29

    Knockout Force notify subscribers of an observable when setting new value

HotTag

Archive