I heave this in html tbody data-bind="foreach: contacts"
and Knockout view model
var viewModel = function () {
$this = this;
$this.contacts = ko.observableArray();
$this.nextPage = function () {
$.ajax({
url: "/api/AddressBook",
data: { pagesize: pageSize, currentpage: CPage },
type: "GET"
}).done(function (data) {
var myKoObservableArray = $this.contacts;
myKoObservableArray.push(null);
myKoObservableArray.push(data);
alert(data[0].Name);
});
}
$(document).ready(function () {
$.ajax({
url: "/api/AddressBook",
data: { pagesize: 10,currentpage: 0 },
type: "GET"
}).done(function (data) {
var vm = new viewModel();
vm.contacts(data);
ko.applyBindings(vm);
});
});
First time page is loaded, table is filled from ajax call from $(document).ready. When I call nextPage from UI I make ajax call and alert(data[0].Name) show first element from returned data array. Is is different collection returned from server each time. The problem is that my table in UI not changed after change "contacts" observable array from second(and next) ajax call.
Problem was that script file was included twice - at header and at bottom of the page. This probably broke binding.