Knockout.js 敲除ForEach和可观测阵列

Knockout.js 敲除ForEach和可观测阵列,knockout.js,foreach,ko.observablearray,Knockout.js,Foreach,Ko.observablearray,在我的视图模型中,我有以下更新数组的代码 self.notesTable = ko.observableArray(); self.SelectedCustomer.subscribe(function () { var x = document.getElementById('customerselect').value; if (x != "Select A Customer") { var notes = GetNotes(x); c

在我的视图模型中,我有以下更新数组的代码

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>

在这里,你真的没有做好成功的准备。您有一个包含对象数组的数组。您应该运行一个循环,将对象推入可观察对象,或者您需要查看数组[0][0],然后查看该对象的内部

我建议你把所有的东西从你的第一个数组中取出,放入可观察的数组中


也许还有更好的方法来解决这个问题,但我还没有真正考虑过,只是回答了眼前的问题

格式化后,它更清晰。您有一个数组,其中包含7项,第一个数组显示为包含7项的数组。你的数据结构让你迷失了方向。
GetNotes
实际上返回了什么?当您“log notesTable”时,您是在执行
console.log(notesTable)
还是
console.log(notesTable())
?是的,在我的GetNotes函数中,我实际上是在数组中构建一个数组。我把它修好了,它工作起来很有魅力。谢谢大家!你说得对。在我的GetNotes函数中,我在一个数组中构建了一个对象数组。我修好了,效果很好。谢谢
[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