简体   繁体   中英

Knockout Observable Array Not Updating

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);

      }
});

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM