I have been searching Google to get some ideas and I found some code but it's incomplete and hard to understand. I want to use knockout to bind a list of images.
What's the best way to set up a spinner background while the images are loading. I have a spinner class I can set and unset to the background image.
Here is the code but it's not clear
ko.bindingHandlers.Loading = {
update: function (element, valueAccessor, allBindingsAccessor) {
var value = valueAccessor(), allBindings = allBindingsAccessor();
var valueUnwrapped = ko.utils.unwrapObservable(value);
if (valueUnwrapped == true)
$(element).showLoading(); // Make the element visible
else
$(element).hideLoading(); // Make the element invisible
}
};
and then use it like
<div data-bind="Loading: isLoading" >
update
<img src="http://www.aero-sa.com/images/ajax-loader.gif" data-bind="visible:loading" />
var model = function() {
var self = this;
this.loading = ko.observable(true);
setTimeout(function() {
self.loading(false);
}, 4000);
}
ko.applyBindings(new model());
i have few question on the above code. what is this here? this point to what? when i write the code like then image is not getting hide....why this is not working.
var model = function() {
//var self = this;
this.loading = ko.observable(true);
setTimeout(function() {
this.loading(false);
}, 4000);
}
ko.applyBindings(new model());
please explain if possible.