[英]Need help -> Uncaught (in promise) TypeError: Cannot read property 'length' of undefined
I have a website and when I am trying to create new content and choose a category I have an error. 我有一个网站,当我尝试创建新内容并选择类别时,出现错误。 Did you happend to have this issue before?
您之前是否碰巧遇到过此问题?
I dont know to resolve this. 我不知道解决这个问题。
setHierarchyPaths: function (categories, path) {
for (var i = 0; i < categories.length; i++) {
if (typeof path !== 'undefined') {
categories[i].path = path + '.' + categories[i].id;
} else {
categories[i].path = categories[i].id;
}
if (categories[i].childrens.length > 0) {
this.setHierarchyPaths(categories[i].childrens,
categories[i].path);
}
// We need a flat tree!
this.flatTree.push(categories[i]);
}
},
I have uploaded the error on these 2 pictures. 我已在这2张图片上上传了错误。 Hope you can help me with this.
希望你能帮我这个忙。 https://www.screencast.com/t/PWjbxIgJe
https://www.screencast.com/t/PWjbxIgJe
https://www.screencast.com/t/Jt2RN08G https://www.screencast.com/t/Jt2RN08G
Many thanks 非常感谢
This is a quite common kind of error. 这是一种非常常见的错误。 It happens when you try to access the attribute (or method) of an object that does not exist.
当您尝试访问不存在的对象的属性(或方法)时,会发生这种情况。
An example 一个例子
const myObject: SomeObject;
if ( myObject.length === 0) {... }
In this case myObjec
is declared but still undefined. 在这种情况下,
myObjec
已声明,但仍未定义。
So, as a result, the length
attribute is called on undefined. 因此,结果是在未定义的情况下调用了
length
属性。 And you will get the error "cannot read property length of undefined". 并且您将得到错误“无法读取未定义的属性长度”。
In your case, please check how the method setHierarchyPaths
is called, because it seems (as jonrsharpe already said in the comment), that the parameter categories
was provided with an undefined value. 在您的情况下,请检查方法
setHierarchyPaths
的调用方式,因为(如jonrsharpe在评论中已经说过的那样)似乎为参数categories
提供了未定义的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.