Skip to content

Instantly share code, notes, and snippets.

@JefClaes
Created March 7, 2014 19:58
Show Gist options
  • Select an option

  • Save JefClaes/9418765 to your computer and use it in GitHub Desktop.

Select an option

Save JefClaes/9418765 to your computer and use it in GitHub Desktop.
A generic self-contained self-refreshing knockout.js model for binding to a dashboard widget.
var ajaxWidgetModel = function (options) {
var self = this;
self.data = ko.observable();
self.tick = function () {
$.get(options.url, function (data) {
self.data(ko.mapping.fromJS(data));
});
};
self.tick();
setInterval(self.tick, options.interval);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment