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. Hope you can help me with this. https://www.screencast.com/t/PWjbxIgJe
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.
So, as a result, the length
attribute is called on undefined. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.