Acceda a los datos json fuera de $ .getJSON ()
$(document).ready(function () {
var value = getParmsVals()["search"];
$.getJSON('/api/search/GetQuestionByKey/' + value, function (jsonData) {
$(jsonData).each(function (i, item) {
var name = getAuthorName(item.userId);
});
});
});
function getAuthorName(userId) {
var fullname = "default";
$.getJSON('/api/search/GetUserById/' + userId, function (jsonData) {
fullname = jsonData.firstname + " " + jsonData.lastname;
});
return fullname;
}
Estoy intentando acceder a la variable de nombre completo llamando al método getAuthorName pero no pude obtener el valor correcto. Siempre me está dando el valor "por defecto".