From 724c011e4c574b301c79358707c364426dac76f2 Mon Sep 17 00:00:00 2001 From: sight <26325820+Sight-wcg@users.noreply.github.com> Date: Fri, 5 Apr 2024 00:24:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(treeTable):=20=E5=88=A0=E9=99=A4=E5=AD=90?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E6=97=B6=EF=BC=8C=E5=86=85=E9=83=A8=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E6=9C=AA=E5=90=8C=E6=AD=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/treeTable.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/modules/treeTable.js b/src/modules/treeTable.js index 7305c555..df398cf9 100644 --- a/src/modules/treeTable.js +++ b/src/modules/treeTable.js @@ -1266,8 +1266,32 @@ layui.define(['table'], function (exports) { }) tableView.find(indexArr.join(',')).remove(); // 删除行 + + var tableCache = table.cache[id]; + var deleteCacheKey = function(type){ + var isUnused = type === 'unused'; + var delNodeDataIndex = delNode[LAY_DATA_INDEX]; + + for (var key in tableCache) { + // 根节点 getNodeDataByIndex 内部已处理 + if(key.indexOf('-') !== -1){ + // 1. L93 updateCache() 中,cacheKey 取自 rowData 中的 LAY_DATA_INDEX, + // 两者不同说明当前 cacheKey 引用的 rowData 已被更新 + // 2. 清理子节点 cacheKey + var shouldCleanup = isUnused ? key !== tableCache[key][LAY_DATA_INDEX] : key.indexOf(delNodeDataIndex) === 0; + if(shouldCleanup){ + delete tableCache[key] + } + } + } + } + + // 清理子节点 key + deleteCacheKey('childNode') // 重新整理数据 var tableData = that.initData(); + // 清理过期的 key + deleteCacheKey('unused') // index发生变化需要更新页面tr中对应的lay-data-index 新增和删除都要注意数据结构变动之后的index问题 layui.each(that.treeToFlat(tableData), function (i3, item3) { if (item3[LAY_DATA_INDEX_HISTORY] && item3[LAY_DATA_INDEX_HISTORY] !== item3[LAY_DATA_INDEX]) {