I am very new in knockout js and have been trying to refresh the Grid using knockout. here is my view model
var GridViewModel = function () {
var _this = {};
_this.mainData = ko.observableArray();
_this.DataFromServer= function()
{
var _transactions = $.getJSON('/data/getData', '', function (response) {
if (response) {
var results = ko.observableArray();
_this.mainData.removeAll();
results = response.mainData;
for (var i = 0; i < results.length; i++) {
_this.mainData.push(results[i]);
};
}
});
}
ko.applyBindings(_this);
_this.DataFromServer();
return _this;
}
var viewModel = GridViewModel();
Above code works fine and binds the data from server to grid but I am not sure how to bind this again after every 10 secs
I have been using the setInterval after Viewmodel call like this
var viewModel = GridViewModel();
setInterval(new GridViewModel(), 10000);
but this is not working. please advise.
Never mind , found the solution. Moved the AJAX method out of ViewModel and called it seperatly during AJAX calls.