Goal:
I'm exploring the Javascript API for Office (for Office 2013), and running into an odd problem. I can't seem to get variables returned up the chain of functions. Example, the API gives a way to check and see all bindings currently associated with the document, using this:
Office.context.document.bindings.getAllAsync(function (asyncResult) {});
I'm trying to use that in a function to get that data as a variable so that I can call certain bindings.
Problem:
I can call my display function inside the innermost function of the API call, and use that to display the result. I can't seem to return that data upwards though.
What I've Tried:
I've tried declaring a variable in the wrapper function, outside the API call. I've tried having two return statements. I feel like this should work:
function getBindings () {
var bindingString;
Office.context.document.bindings.getAllAsync(function (asyncResult) {
for (var i in asyncResult.value) {
bindingString += asyncResult.value[i].id;
}
});
return 'Bindings: '+bindingString[0];
}
Unfortunately that just returns this:
Bindings: undefined
I know that inside the innermost function, I have data, because I've placed a call to my display function from inside, and had the bindings written to the page. I could therefore just creating a hidden holding ` that I fill and then read. I feel like that would be a hack though.
Question:
Is there a better way to return the variable?