資料結構是這樣的
{
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="https://bbs.csdn.net/topics/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"
拜托各位大牛,看一下,謝謝啦
uj5u.com熱心網友回復:
let定義只在塊級作用域起作用,用var
let child1 = [];
let child2 = [];
uj5u.com熱心網友回復:
非常感謝您的回復,我試了還是一樣報錯轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/67176.html
標籤:JavaScript
