Я пытался мысленно использовать замыкание, но это просто вылетало из головы. Он дает мне не строку, а объект.
Логика следующая.
Код: Выделить всё
function P(i){
var x;
if(i!=null){
//this pulls the data correctly and i could see it in network tab response.
var dataFromQuery=widgets.DATA.create({
url:"abc/cde",
queryTemplate :"/query"+i+ "?"
});
//we query the data and set the value as per the logic.
dataFromQuery.query(function(data){
if(data[0].name){
x=data[0].name; // this stays undefined , and i understand this is a new local variable x.Also the value is here and comes fine here so no issues with the data but i want to set it to the variable defined outside as x.
}
})
}
else{
x="somehardcode";
}
};
Спасибо
Подробнее здесь: https://stackoverflow.com/questions/402 ... ested-func
Мобильная версия