0
votes

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
Did you try console.log(self.notesTable()); ?Paul D.
Observables are functions, not values. You must call them to see or change the underlying value.Tomalak
@Paul that works...thanks so much!user3062114
@Tomalak your answer is right also, essentially i was not calling my observable array as a function but a value. Thanks!user3062114

1 Answers

0
votes

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