Knockout Observable Array Not Updating

460 Views Asked by At

Using Knockout.JS 3.0, I am trying to create an observable array and then update that array in my SelectedCustomer.subscribe function. My variable notes loads fine and this is what it returns in my console log: [Array[7]] but when I log my observableArray notesTable it only logs []. Basically, I have a foreach binding that creates a table based on the array and it's not loading any data.

self.notesTable = ko.observableArray();



self.SelectedCustomer.subscribe(function () {
    var x = document.getElementById('customerselect').value;

    if (x != "Select A Customer") {

        var notes = GetNotes(x);

        console.log("notes =");
        console.log(notes);

        self.notesTable(notes);
        console.log(self.notesTable);

      }
});
1

There are 1 best solutions below

0
On

As the comments suggest - You need to call this as console.log(self.notesTable());

the documentation for ko.obervableArray don't explicitly state this - http://knockoutjs.com/documentation/observableArrays.html

It's implied from the ko.observable docs listed here - http://knockoutjs.com/documentation/observables.html#reading_and_writing_observables