From 32e24837160688c1d39d2e74dba62ae1ec9bc74c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Sat, 29 Jul 2023 11:38:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=20treeTable=20=E7=9A=84=20`c?= =?UTF-8?q?ascade`=20=E5=B1=9E=E6=80=A7=E9=80=BB=E8=BE=91=E4=B8=8E?= =?UTF-8?q?=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/treeTable.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/modules/treeTable.js b/src/modules/treeTable.js index 6bb60a4a..8f644431 100644 --- a/src/modules/treeTable.js +++ b/src/modules/treeTable.js @@ -203,9 +203,9 @@ layui.define(['table'], function (exports) { Class.prototype.init = function () { var that = this; var options = that.config; - var cascade = options.tree.check.cascade; - if (cascade !== 'parent' || cascade !== 'children') { - options.tree.check.cascade = 'all'; // 超出范围的都重置为全联动 + var cascade = options.tree.data.cascade; + if (cascade !== 'parent' && cascade !== 'children') { + options.tree.data.cascade = 'all'; // 超出范围的都重置为全联动 } // 先初始一个空的表格以便拿到对应的表格实例信息 @@ -247,7 +247,8 @@ layui.define(['table'], function (exports) { }, data: { isSimpleData: false, // 是否简单数据模式 - rootPid: null // 根节点的父 ID 值 + rootPid: null, // 根节点的父 ID 值 + cascade: 'all' // 级联方式 默认全部级联:all 可选 级联父 parent 级联子 children }, async: { enable: false, // 是否开启异步加载模式,只有开启的时候其他参数才起作用 @@ -261,9 +262,6 @@ layui.define(['table'], function (exports) { callback: { beforeExpand: null, // 展开前的回调 return false 可以阻止展开的动作 onExpand: null // 展开之后的回调 - }, - check: { - cascade: 'all' // 级联方式 默认全部级联:all 可选 级联父 parent 级联子 children } }, }; @@ -1404,7 +1402,7 @@ layui.define(['table'], function (exports) { }); var isAll = true; - layui.each(treeOptions.check.cascade === 'all' ? table.cache[id] : treeTable.getData(id, true), function (i1, item1) { + layui.each(treeOptions.data.cascade === 'all' ? table.cache[id] : treeTable.getData(id, true), function (i1, item1) { if (!item1[checkName]) { isAll = false; return true; @@ -1516,7 +1514,7 @@ layui.define(['table'], function (exports) { var checkName = table.config.checkName; - var cascade = treeOptions.check.cascade; + var cascade = treeOptions.data.cascade; var isCascadeParent = cascade === 'all' || cascade === 'parent'; // 如有必要更新父节点们的状态 @@ -1540,7 +1538,7 @@ layui.define(['table'], function (exports) { // 更新全选的状态 var isAll = true; var isIndeterminate = false; - layui.each(treeOptions.check.cascade === 'all' ? table.cache[tableId] : treeTable.getData(tableId, true), function (i1, item1) { + layui.each(treeOptions.data.cascade === 'all' ? table.cache[tableId] : treeTable.getData(tableId, true), function (i1, item1) { if (item1[checkName] || item1[LAY_CHECKBOX_HALF]) { isIndeterminate = true; } @@ -1684,7 +1682,7 @@ layui.define(['table'], function (exports) { } } - var trs = that.updateStatus(trData ? [trData] : table.cache[tableId], checkedStatusFn, trData && treeOptions.check.cascade === 'parent'); + var trs = that.updateStatus(trData ? [trData] : table.cache[tableId], checkedStatusFn, trData && treeOptions.data.cascade === 'parent'); var checkboxElem = tableView.find(trs.map(function (value) { return 'tr[lay-data-index="' + value[LAY_DATA_INDEX] + '"] input[name="layTableCheckbox"]:not(:disabled)'; }).join(','));