Created
December 21, 2014 21:53
-
-
Save devdays/3758d46ea5262a69292b to your computer and use it in GitHub Desktop.
Single Page App - IsLoading snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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