knockout.js - Add loading image when use getJSON -
when page loaded, script call api list data.
function accounttypeviewmodel() { var self = this; self.list = ko.observablearray(); self.selecteditems = ko.observablearray(); var baseuri = 'url'; $.getjson(baseuri, self.list); } ko.applybindings(new accounttypeviewmodel()); when use method getjson, mapping data server self.list. how use callback method binding? use dynamic binding. want show image loading util getjson done.
thanks in advance..
you calling $.getjson observablearray function success callback. fact sets observable value because ko expects 1 argument , ignore remaining arguments.
you should supply success function, or (preferrable) use jquery promise.
$.getjson( baseuri ) .done( function(data, status) { self.list(data); }) .always( function() { // called on either success or failure // clear loading image here });
Comments
Post a Comment