当数组是对象数组,赋值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;
}