el-table 在用到 :tree-props的时,对其子组件做删除修改处理时,出现了。children undefind

翛翾梓 2020-04-11 03:25:50
数据结构是这样的
{
id: 1,
date: "2016-05-02",
name: "sdsd对数函数的 ",
levels: 1,
address: "上海市普陀区金沙江路 1518 弄",
children: [
{
id: 11,
date: "2016-05-01",
name: "万二份",
levels: 2,
address: "上海市普陀区金沙江路 1519 弄",
children: [
{
id: 111,
date: "2016-05-01",
levels: 3,
name: "王三",
address: "上海市普陀区金沙江路 1519 弄"
}
]
}
]
},


表单组件
 <el-table
:data="tableData"
style="width: 100%;margin-bottom: 20px;"
row-key="id"
stripe
ref="refs"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
>


我写的方法是这样的

sortDelet(row) {
// console.log(this);
console.log(row);
console.log(row.levels);

if (row.levels * 1 == 1) {
this.tableData.splice(this.tableData.indexOf(row), 1);
} else if (row.levels * 1 == 2) {
// debugger;
let child1 = [];
for (let i = 0; i <= this.tableData.length; i++) {
child1 = this.tableData[i].children;
for (let j = 0; j < child1.length; j++) {
if (child1[j].id * 1 == row.id*1) {
child1.splice(child1.indexOf(child1[j]), 1);
}
}
}
} else if (row.levels * 1 == 3) {
let child1 = [];
let child2 = [];
for (let i = 0; i <= this.tableData.length; i++) {


child1 = this.tableData[i].children;
for (let j = 0; j < child1.length; j++) {
child2 = this.tableData[i].children[j].children;
for (let k = 0; k < child2.length; k++) {
if (child2[k].id * 1 == row.id*1) {
child2.splice(child2.indexOf(child2[k]), 1);
}
}
}
}
}
}


报错是这样的
但是奇怪的是,功能实现了,但是一直报错,
Error in v-on handler: "TypeError: Cannot read property 'children' of undefined"


拜托各位大牛,看一下,谢谢啦
...全文
1274 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
翛翾梓 2020-04-12
  • 打赏
  • 举报
回复
非常感谢您的回复,我试了还是一样报错
console.log( ) 2020-04-11
  • 打赏
  • 举报
回复
let定义只在块级作用域起作用,用var

 let child1 = [];
        let child2 = [];

87,995

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧