Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 21, 2014 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdays/3758d46ea5262a69292b to your computer and use it in GitHub Desktop.
Save devdays/3758d46ea5262a69292b to your computer and use it in GitHub Desktop.
Single Page App - IsLoading snippet
// Create the model and the viewModel
var model = [];
var viewModel = {
products: ko.observableArray(model)
};
// When the page is ready, set up the loading indicator
// and load the data
$(document).ready(function () {
// Set the myProducts element to receive the loading indicator
$("#myProducts").isLoading({
text: "Loading",
position: "inside",
});
// Load the data into the model
$.getJSON(
"/api/products/",
function (model) {
// Do something that take a couple seconds so we can
// see the spinner
var a = 0;
setTimeout(function () {
var b = a * 5000;
}, 2000);
// Hide the loading indicator
$("#myProducts").isLoading("hide");
// Bind the data to the viewModel
viewModel.products(model);
}
);
// Apply the Knockout bindings
ko.applyBindings(viewModel);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment