JSON JQUERY未捕获类型错误:无法读取属性'长度'的未定义
JSON JQUERY Uncaught TypeError: Cannot read property 'length' of undefined
我是编程新手。我正在尝试使用JQuery将JSON数据显示到HTML文件中。我在控制台中收到一个Uncaught TypeError: Cannot read property 'length' of undefinedresumeBuilder.js:147 education.displayresumeBuilder.js:178 (anonymous function)
错误,我不知道为什么。如果你能澄清这个错误,我们将不胜感激!
这是我的简历Builder.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>';
您的第一个JSON对象中似乎有一个拼写错误。
var eduction = {
应该有一个"a"。
您错过了教育-教育第1行
您的var eduction = {
=>var education = {
中有一个打字错误
您可能还想更改:
var HTMLonlineClasses = '<h3>Online Classes</h3>';
以匹配您在javascript中比较的变量。
education.onlineCourses
var HTMLonlineCourses = '<h3>Online Courses</h3>';
因此,在未来,查找和更新对该变量的引用将更容易
相关文章:
- TypeError:无法读取属性'推'未定义的JavaScript
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 未捕获的类型错误:无法读取属性'删除'的未定义
- AngularJS指令出错-无法读取属性'编译'的未定义
- 未捕获的类型错误:无法读取属性'name'即使它存在,也无法定义
- 看到“;未捕获的类型错误:无法读取属性'weight'未定义的“;尽管按照字面上的指示
- angularjs无法读取未定义的属性then
- 无法读取属性'材料'未定义的Three.js
- 得到"TypeError:无法读取属性'filename'未定义的“;调用“npm start
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- 未捕获的类型错误:无法读取属性'addEventListener'的null chrome扩展名
- Soundcloud Javascript SDK 3.0-回调无法读取属性'connectCallback
- 未捕获的类型错误:无法读取属性'状态'在react中为null
- JavaScript承诺-无法读取属性'那么'的未定义
- Javascript Float32数组抛出无法读取属性'0'即使数组定义良好,也为null
- 未捕获的类型错误:无法读取属性'中止'的未定义
- 角度推入数组给出:TypeError:无法读取属性'推'的未定义
- http/rxjs catch回调中的Angular 2重定向导致TypeError:无法读取属性'订阅'
- 角度输入模型有条件地从一个属性读取,写入另一个属性