function CustomerRefresher(id){
var refresh = function(){
$.getJSON('/ApiCustomer/Get/' + encodeURIComponent(id), function(data){
if (typeof CustomerRefresher.viewModel !== 'undefined'){
ko.mapping.fromJS(data, {}, CustomerRefresher.viewModel);
}else{
CustomerRefresher.viewModel = ko.mapping.fromJS(data);
ko.applyBindings(CustomerRefresher.viewModel);
}
setTimeout(refresh, 10000);
});
};
refresh();
}
Something like that? (can use the function itself to "cache" the view model) Also, example provided.
Also, FWIW, this is probably better suited for codereview.SE.