更多帮助,不同的问题。我想从内部循环返回 allLessonsArray,但由于某种原因它没有到达循环函数之外。我已经注意到它在哪里起作用,在哪里不起作用。我如何将其返回到外部?
var allLessonsArray= new Array();
$.each(lessonInTopicSectionArray, function(index, lesson){
var lastAttempt = 0;
url='domain/learn/mod/lesson/report.php?id='+lesson.id+'&action=reportdetail&userid='+userid+'&try='+lastAttempt;
$.get(url, function(data) {
var lessonArray= new Array();
$(data).find('tr.r1.lastrow td.cell.c0')
.each(function(index, content) {
var string=jQuery(content).html()
score=parseInt(string.substr(string.length - 1));
lessonArray[index]=score;
});
allLessonsArray[index]={name:lesson.name, score: lessonArray};
//This works.
alert(allLessonsArray[0].name);
alert(allLessonsArray[0].score[0]);
});
//This doesn't work.
alert(allLessonsArray[0].name);
alert(allLessonsArray[0].score[0]);
});
return allLessonsArray;