From 54e35f2204090672abcbae3e46f7cd94ba3c2dc7 Mon Sep 17 00:00:00 2001 From: morning-star <26325820+Sight-wcg@users.noreply.github.com> Date: Fri, 26 Apr 2024 16:32:00 +0800 Subject: [PATCH] =?UTF-8?q?fix(treetable):=20=E4=BF=AE=E5=A4=8D=20treeTabl?= =?UTF-8?q?e=20=E7=94=B1=20#1808=EF=BC=8C#1792=20=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E9=97=AE=E9=A2=98=20(#1828)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(treeTable): 重载时格式化图标异常 * fix(treeTable): 异步加载时, 加载图标异常 * fix(treeTable): 异步加载节点异常 related: #1792 --- src/modules/treeTable.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/modules/treeTable.js b/src/modules/treeTable.js index 2c62f99a..6ae1bc69 100644 --- a/src/modules/treeTable.js +++ b/src/modules/treeTable.js @@ -213,9 +213,13 @@ layui.define(['table'], function (exports) { } // 处理图标 - layui.each(ICON_PROPS, function(i, iconProp){ - options.tree.view[iconProp] = that.normalizedIcon(options.tree.view[iconProp]); - }) + if(options && options.tree && options.tree.view){ + layui.each(ICON_PROPS, function(i, iconProp){ + if(options.tree.view[iconProp] !== undefined){ + options.tree.view[iconProp] = that.normalizedIcon(options.tree.view[iconProp]); + } + }) + } } Class.prototype.init = function () { @@ -527,7 +531,9 @@ layui.define(['table'], function (exports) { var update = function(data, parentIndex){ layui.each(data, function (i1, item1) { - item1[isParentKey] = !!(item1[childrenKey] && item1[childrenKey].length); + if (!(isParentKey in item1)) { + item1[isParentKey] = !!(item1[childrenKey] && item1[childrenKey].length); + } item1[LAY_DATA_INDEX_HISTORY] = item1[LAY_DATA_INDEX]; item1[LAY_PARENT_INDEX] = parentIndex = parentIndex || ''; var dataIndex = item1[LAY_DATA_INDEX] = (parentIndex ? parentIndex + '-' : '') + i1; @@ -587,6 +593,7 @@ layui.define(['table'], function (exports) { // 找到表格中的同类节点(需要找到lay-data-index一致的所有行) var trsElem = tableViewElem.find('tr[lay-data-index="' + dataIndex + '"]'); + var flexIconElem = trsElem.find('.layui-table-tree-flexIcon'); treeTableThat.updateNodeIcon({ scopeEl: trsElem, isExpand: trExpand, @@ -1310,6 +1317,8 @@ layui.define(['table'], function (exports) { var options = that.getOptions(); var treeOptions = options.tree; + var isParentKey = treeOptions.customName.isParent; + var childrenKey = treeOptions.customName.children; var tableView = options.elem.next(); var delNode; var indexArr = []; @@ -1360,13 +1369,14 @@ layui.define(['table'], function (exports) { tableView.find('tr[data-level="0"][lay-data-index="' + item4[LAY_DATA_INDEX] + '"]').attr('data-index', i4); }) options.hasNumberCol && formatNumber(that); - // 更新父节点图标状态 + // 更新父节点状态 if(nodeP){ var trEl = tableView.find('tr[lay-data-index="' + nodeP[LAY_DATA_INDEX] + '"]'); + nodeP[isParentKey] = !!(nodeP[childrenKey] && nodeP[childrenKey].length); that.updateNodeIcon({ scopeEl: trEl, isExpand: nodeP[LAY_EXPAND], - isParent: nodeP[treeOptions.customName.isParent], + isParent: nodeP[isParentKey], }); }