var viewModel = {
foos: ko.observableArray([]);
}
var foo = function () {
this.Prop1 = ko.observable,
this.Prop2 = ko.observable
};
$.get("/someroute/", "", function(data) {
for(var i = 0; i< data.length; i++) {
var f = new foo();
f.Prop1 = data.Prop1;
f.Prop2 = data.Prop2;
viewModel.foos.push(f);
}
ko.applyBindings(viewModel);
});
数据从 get 请求加载并循环遍历数据,但 viewModel.foos 保持为 [0]。