I have a Knockout binding to my function:
<tr id="toolbarRow" data-bind="foreach: get_tabs()">
get_tabs
calls load
which uses an ajax request to populate the departments
variable:
get_tabs = function () {
load();
return departments;
},
This causes me a problem as get_tabs
returns before departments
is populated by load
.
Here's load
:
load = function () {
$.ajax(
{
url: _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?querytext='Department:*"
+ "*'&selectproperties='Department'&sourceid='B09A7990-05EA-4AF9-81EF-EDFAB16C4E31'&sortlist='Department:ascending'",
method: "GET",
headers: {
"accept": "application/xml",
},
success: onSuccess,
error: onError
}
);
},
onSuccess = function (data) {
...populating departments variable...
},
onError = function (err) {
alert("something blew up");
},
How can I keep get_tabs
from returning until my ajax request finishes the onSuccess
event?