Question

In my view model I have the following code updating an array.

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



       }
});


<tbody data-bind="foreach: notesTable" >
                        <tr>
                            <td data-bind="text: Note_Number"></td>

In my HTML I have the above for each statement. My problem is that when I log notesTable it shows the following. But my for each fails to update and says Note Number is not defined?

[Array[7]]
0: Array[7]
0: Object
Note_Date: "7/31/2008 12:00:00 AM"
Note_Number: "27753"
Note_Resolved: "True"
Note_Resolved_Date: "4/14/2009 12:00:00 AM"
Note_Text: "SENT INVOICE COPIES TO MARTY 7/8/08"
Note_Time: "11:17:23"
Note_User: "RUSSA  
Was it helpful?

Solution

You really aren't setup for success here. You have an array with o e array of objects. You should run a loop to push the objects into the observable, or you will need to look at the array[0][0] then look inside that object.

I would suggest pulling everything out of your first array and put in the observable.

There may also be a better way to approach this all together, but I haven't really thought about it, just answering the problem at hand.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top