Knockout Modifying ObservableArray inside Computed

Frank Conry

I am trying to solve the problem where I have a two way computed observable and want that parsed into an observable array and have that change event bubble up. The problem is that the it appear to not be notifying subscribers.

Its best shown in jsfiddle: http://jsfiddle.net/RHhmY/13/

Code here:

function CustomerOverview() {
    var self = this;

    self.contacts = ko.observableArray([]);
    self.v = ko.computed(
        {
            read : function(){
            return "";
            },
             write : function(val){
               self.contacts = ko.observableArray(String(val).split(','));
             }
        }
    );
};



var vm = new CustomerOverview();
ko.applyBindings(vm);

and html:

LENGTH<span data-bind="text: contacts.length"></span><br />
<input type="text" data-bind="value: v">

I have tried a number of things including notifying subscribers of the observableArray in question and the length never updates.

As a side not, I'm very open to changing how this is constructed wrt knockout, just want something that works.

GôTô

This breaks your binding:

write : function(val){
           self.contacts = ko.observableArray(String(val).split(','));
}

You want to update your observable instead of re-assigning it

write : function(val){
           self.contacts(String(val).split(','));
}

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 Modifying ObservableArray inside Computed

From Dev

Knockout computed observable with access to observableArray

From Dev

knockout.js observableArray computed value

From Dev

Knockout JS - Modifying properties of items in observableArray

From Dev

Remove an element from observableArray inside another observableArray in knockout

From Dev

How to remove a piece of an observableArray inside a loop with knockout?

From Dev

Asynchronous call inside a Knockout computed function

From Dev

Modifying values inside data-bind in knockout

From Dev

Knockout: Update item in an observableArray

From Dev

Knockout not create and observableArray

From Dev

Filtering an observableArray in Knockout

From Dev

Knockout observableArray is not binding correctly

From Dev

Knockout observableArray push not working

From Dev

Load Knockout observableArray not working

From Dev

Knockout observableArray not updating UI

From Dev

How to use computed method inside foreach in knockout.js

From Dev

Put computed value inside progress bar Knockout js

From Dev

How to use computed method inside foreach in knockout.js

From Dev

ko.Computed() is not updating with observableArray

From Dev

Modifying value of observable values in observableArray

From Dev

Knockout move observableArray item down

From Dev

Save Knockout observableArray JSON to localStorage

From Dev

knockout.js: No concat on observableArray

From Dev

Knockout ObservableArray not updating HTML Foreach

From Dev

Custom filtering knockout js observableArray

From Dev

Sum values in nested knockout observableArray

From Dev

Knockout.js contenteditable observablearray

From Dev

knockout.js: No concat on observableArray

From Dev

Knockout ObservableArray not updating HTML Foreach

Related Related

  1. 1

    Knockout Modifying ObservableArray inside Computed

  2. 2

    Knockout computed observable with access to observableArray

  3. 3

    knockout.js observableArray computed value

  4. 4

    Knockout JS - Modifying properties of items in observableArray

  5. 5

    Remove an element from observableArray inside another observableArray in knockout

  6. 6

    How to remove a piece of an observableArray inside a loop with knockout?

  7. 7

    Asynchronous call inside a Knockout computed function

  8. 8

    Modifying values inside data-bind in knockout

  9. 9

    Knockout: Update item in an observableArray

  10. 10

    Knockout not create and observableArray

  11. 11

    Filtering an observableArray in Knockout

  12. 12

    Knockout observableArray is not binding correctly

  13. 13

    Knockout observableArray push not working

  14. 14

    Load Knockout observableArray not working

  15. 15

    Knockout observableArray not updating UI

  16. 16

    How to use computed method inside foreach in knockout.js

  17. 17

    Put computed value inside progress bar Knockout js

  18. 18

    How to use computed method inside foreach in knockout.js

  19. 19

    ko.Computed() is not updating with observableArray

  20. 20

    Modifying value of observable values in observableArray

  21. 21

    Knockout move observableArray item down

  22. 22

    Save Knockout observableArray JSON to localStorage

  23. 23

    knockout.js: No concat on observableArray

  24. 24

    Knockout ObservableArray not updating HTML Foreach

  25. 25

    Custom filtering knockout js observableArray

  26. 26

    Sum values in nested knockout observableArray

  27. 27

    Knockout.js contenteditable observablearray

  28. 28

    knockout.js: No concat on observableArray

  29. 29

    Knockout ObservableArray not updating HTML Foreach

HotTag

Archive