I am having trouble managing my data when calling API web services because the result of AJAX result comes in last. To have a better picture, see code below:
this.variable = ko.observableArray();
this.getAPI = function(){
$.getJSON("<api_url>", function(result){
console.log("api result");
this.variable(result);
});
console.log("call api");
}
this.setTable = function(){
this.getAPI();
console.log(this.variable());
console.log("set table");
}
CONSOLE:
call api
[ ]
set table
api result
Do you guys have any idea what is the proper way of doing this type of programming setup?