이것은 기본적인 JQuery/Javascript 질문입니다. 어떻게 getJSON 함수에서 데이터를 가져 옵니까?
다음 코드는 함수가 끝날 때까지 훌륭하게 작동합니다. 나는 한 후 - 더 - 기타를 실행해야합니다 여러해서 getJSON을하고 난 내가 할 수있는 경우를 중첩 피하기 위해 싶습니다
//Using the Web API to pull all the information out for the current ORG ID
$.getJSON('http://localhost:8081/dhis/api/organisationUnits/' + vuCurrentFacilityID + '.json', function (data) {
//alert(data.message);
console.log(data);
vuCurrentFacilityName = data.name;
vuParentFacilityID = data.parent.name;
});
alert(vuCurrentFacilityName); //does not work
잡았다 * 나는 무엇을 놓치고? 이 질문은 매우 similar to the following입니다.
내 문제를 해결 http://stackoverflow.com/questions/6922237/scope-for-getjson-in-jquery?rq=1, 보이지 않는 대신 deferreds getJSON에서 데이터를 가져 오는 것이 좋습니다. 그것을 중첩하는 것은 그 때이다! –