From a410eb2dca70fce6003a55e1472c1f4e7ef9869a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Sun, 12 Jan 2020 09:57:40 +0800 Subject: [PATCH] fix tree table showChildren --- src/components/table/table-body.vue | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/components/table/table-body.vue b/src/components/table/table-body.vue index dbbaaf76..c359cce3 100644 --- a/src/components/table/table-body.vue +++ b/src/components/table/table-body.vue @@ -146,6 +146,7 @@ }, isTrShow (rowKey) { let status = true; + let child; for (let i in this.objData) { const row = this.objData[i]; const showChildren = row._isShowChildren; @@ -153,25 +154,34 @@ status = status && showChildren; break; } else if (row.children && row.children.length) { - status = this.getTrStatus(rowKey, row, status && showChildren); - return status; + child = this.getTrStatus(rowKey, row, status && showChildren); + if (child[0] && child[0]._rowKey === rowKey) { + return child[1]; + } } } return status; }, getTrStatus (rowKey, data, parentStatus) { let status = parentStatus; + let childData; if (data.children && data.children.length) { - data.children.forEach(row => { + for (let i = 0; i < data.children.length; i++) { + const row = data.children[i]; const showChildren = row._isShowChildren; if (row._rowKey === rowKey) { + childData = row; status = status && showChildren; + break; } else if (row.children && row.children.length) { - status = this.getTrStatus(rowKey, row, status && showChildren); + const child = this.getTrStatus(rowKey, row, status && showChildren); + if (child[0] && child[0]._rowKey === rowKey) { + return child; + } } - }); + } } - return status; + return [childData, status]; }, getLevel (rowKey) { let level;