From ca574d1c11061b99eba02a76fad8769eb68a1aed Mon Sep 17 00:00:00 2001 From: morning-star Date: Sat, 7 Oct 2023 09:30:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20treeTable=20=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=20treeTable.setRowChecked=20=E6=9C=AA=E9=80=90?= =?UTF-8?q?=E5=B1=82=E5=B1=95=E5=BC=80=E4=B8=8A=E7=BA=A7=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20(#1385)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复 treeTable 组件 treeTable.setRowChecked 未逐层展开上级节点的问题 修复 treeTable 组件 treeTable.setRowChecked 未逐层展开上级节点的问题 * Update treeTable.js --- src/modules/treeTable.js | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/modules/treeTable.js b/src/modules/treeTable.js index a62b8045..1bdd7d57 100644 --- a/src/modules/treeTable.js +++ b/src/modules/treeTable.js @@ -1791,14 +1791,30 @@ layui.define(['table'], function (exports) { // 目前只能处理当前页的数据 return; } + + var collectNeedExpandNodeIndex = function(index){ + needExpandIndex.push(index); + var trElem = tableView.find('tr[lay-data-index="' + index + '"]'); + if (!trElem.length) { + var nodeData = that.getNodeDataByIndex(index); + var parentIndex = nodeData[LAY_PARENT_INDEX]; + parentIndex && collectNeedExpandNodeIndex(parentIndex); + } + } + // 判断是否展开过 var trElem = tableView.find('tr[lay-data-index="' + dataIndex + '"]'); if (!trElem.length) { + var parentIndex = nodeData[LAY_PARENT_INDEX]; + var needExpandIndex = []; + collectNeedExpandNodeIndex(parentIndex); // 如果还没有展开没有渲染的要先渲染出来 - treeTable.expandNode(id, { - index: nodeData[LAY_PARENT_INDEX], - expandFlag: true - }); + layui.each(needExpandIndex.reverse(),function(index, nodeIndex){ + treeTable.expandNode(id, { + index: nodeIndex, + expandFlag: true + }); + }) trElem = tableView.find('tr[lay-data-index="' + dataIndex + '"]'); } checkNode.call(that, trElem, checked, callbackFlag);