我是编程新手。我正在尝试使用JQuery将JSON数据显示到HTML文件中。我在控制台中出现了Uncaught TypeError: Cannot read property 'length' of undefinedresumeBuilder.js:147 education.displayresumeBuilder.js:178 (anonymous function)
的错误,我不知道为什么。任何你可以解决这个错误的灯都会非常感谢!JSON JQUERY未捕获TypeError:无法读取未定义的属性“长度”
这里是我的resumeBuilder.js文件:
var eduction = {
"schools": [
{
"name": "McGill University",
"location": "Montreal, Quebec, Canada",
"degree": "Master of Arts",
"major": "Second Language Education",
"url": "mcgill.ca"
}
],
"onlineCourses": [
{
"title": "Full Stack Web Development Course",
"school": "Bloc.io",
"url": "bloc.io"
}
]
};
education.display = function() {
if(education.schools.length > 0 || education.onlineCourses.length > 0) {
for(i in education.schools) {
$("#education").append(HTMLschoolStart);
var formattedSchoolName = HTMLschoolName.replace("%data%", education.schools[i].name).replace("#", education.schools[i].url);
var formattedSchoolDegree = HTMLschoolDegree.replace("%data%", education.schools[i].degree);
var formattedSchoolLocation = HTMLschoolLocation.replace("%data%", education.schools[i].location);
var formattedSchoolMajor = HTMLschoolMajor.replace("%data%", education.schools[i].major);
$(".education-entry:last").append(formattedSchoolName + formattedSchoolDegree);
$(".education-entry:last").append(formattedSchoolLocation);
$(".education-entry:last").append(formattedSchoolMajor);
}
if(education.onlineCourses.length > 0) {
$("#education").append(HTMLonlineClasses);
for(i in education.onlineCourses) {
$("#education").append(HTMLschoolStart);
var formattedOnlineTitle = HTMLonlineTitle.replace("%data%", education.onlineCourses[i].title).replace("#", education.onlineCourses[i].url);
var formattedOnlineSchool = HTMLonlineSchool.replace("%data%", education.onlineCourses[i].school);
var formattedOnlineURL = HTMLonlineURL.replace("%data%", education.onlineCourses[i].url).replace("#", education.onlineCourses[i].url);
$(".education-entry:last").append(formattedOnlineTitle);
$(".education-entry:last").append(formattedOnlineSchool);
$(".education-entry:last").append(formattedOnlineURL);
}
}
}
}
education.display();
这里是我的helper.js文件:
var HTMLschoolStart = '<div class="education-entry"></div>';
var HTMLschoolName = '<a href="#">%data%';
var HTMLschoolDegree = ' -- %data%</a>';
var HTMLschoolLocation = '<div class="location-text">%data%</div>';
var HTMLschoolMajor = '<em><br>Major: %data%</em>';
var HTMLonlineClasses = '<h3>Online Classes</h3>';
var HTMLonlineTitle = '<a href="#">%data%';
var HTMLonlineSchool = ' - %data%</a>';
var HTMLonlineURL = '<br><a href="#">%data%</a>';
你能告诉我们在这个代码行是':178'? – void 2015-02-23 22:18:34