난 작은 프로젝트에 대한 Phonegap Web Storage를 테스트입니다 :JavaScript에서 콜백 함수의 내부 변수를 설정하는 방법은 무엇입니까?
는var listsCount = 0;
tx.executeSql("SELECT * FROM list WHERE id = ?", [id], successGetList, errorGetList);
function successGetList(tx, results){
listsCount = results.rows.length; // this will be 2, in my case
}
function errorGetList(err){
console.log("Error processing SQL: "+err.code);
}
console.log(listsCount); // this will show 0, instead of 2
난 데 문제는 listsCount
가 successGetList
방법 안에 설정되지 않는다는 것입니다. 내가 거기로 돌려 준다해도.
내부 변수를 설정할 수있는 아이디어는 successGetList
입니다.
감사
[함수에서 AJAX 호출의 응답을 반환하는 방법] 가능한 중복?] (http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax- call-from-a-function) (AJAX는 아니지만 동일한 비동기 동작이 적용됩니다.) –
@ FrédéricHamidi 이것은 'return'에 대해서도 묻지 않습니다. 당신은 올바른 대답을 지적해야합니다. 그러나이 질문에 대해서는 너무 많이 할 수도 있습니다. – bfavaretto