前端报错-报错Uncaught (in promise) TypeError: Cannot set properties of undefined (setting ‘children‘)
当数组是对象数组,赋值this.treeData[-1].children = this.SourceList;,报错Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'children')负数索引不适用于对象数组,因为负数索引通常用于访问数组的最后几个元素,而不是对象属性。
·
当数组是对象数组,赋值this.treeData[-1].children = this.SourceList;,报错Uncaught (in promise) TypeError: Cannot set properties of undefined (setting 'children')
原因:负数索引不适用于对象数组,因为负数索引通常用于访问数组的最后几个元素,而不是对象属性。
应该修改如下:
if (this.treeData.length > 0) {
this.treeData[this.treeData.length - 1].children = this.SourceList;
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)