[英]Never ending for loop javascript
为什么这个循环永无止境? 每个节可能有也可能没有子节,这些子节与节是同一类。for语句的工作方式很奇怪。 它直接返回到list.append('<label class="heading">' + theSection.description + '</label><br/><hr><br/>');
每时每刻。 如果没有小节,则不应这样做。
function createAssessmentSectionFormHTML(section) {
var list = $('#assessmentSectionForm' + platform);
appendSection(section, list);
}
function appendSection(theSection, list) {
list.append('<label class="heading">' + theSection.description + '</label><br/><hr><br/>');
appendSectionQuestions(theSection, list);
if (theSection.allSubSections) {
for (x = 0; x < theSection.allSubSections.length; x++) {
var theSectionA = theSection.allSubSections[x];
appendSection(theSectionA, list);
}
return;
}
}
我相信您在for循环中缺少“ var”:
for (var x = 0; x < theSection.allSubSections.length; x++) {
这应该可以解决问题-它可以无限运行,因为未声明x。 未定义的长度总是小于任何长度,因此没有终点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.