From 9359023af46f9fe0b70ca5b1591c9d4e8381b5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Wed, 12 Jul 2023 15:34:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20tree=20=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E5=A4=8D=E9=80=89=E6=A1=86=E6=97=B6=E6=9C=AA=E5=B0=86=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E7=9A=84=E6=95=B0=E6=8D=AE=E4=B8=AD=E7=9A=84=20`check?= =?UTF-8?q?ed`=20=E5=B1=9E=E6=80=A7=E5=80=BC=E8=BF=9B=E8=A1=8C=E5=90=8C?= =?UTF-8?q?=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/tree.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/modules/tree.js b/src/modules/tree.js index a2dd60a7..4fc94a4b 100644 --- a/src/modules/tree.js +++ b/src/modules/tree.js @@ -277,6 +277,7 @@ layui.define('form', function(exports){ var options = that.config; var entry = elem.children('.'+ELEM_ENTRY); var elemMain = entry.children('.'+ ELEM_MAIN); + var elemCheckbox = elemMain.find('input[same="layuiTreeCheck"]'); var elemIcon = entry.find('.'+ ICON_CLICK); var elemText = entry.find('.'+ ELEM_TEXT); var touchOpen = options.onlyIconControl ? elemIcon : elemMain; // 判断展开通过节点还是箭头图标 @@ -324,12 +325,17 @@ layui.define('form', function(exports){ } else { state = options.onlyIconControl ? 'close' : 'open'; } + + // 获取选中状态 + if(elemCheckbox[0]){ + item['checked'] = elemCheckbox.prop('checked'); + } // 点击产生的回调 options.click && options.click({ - elem: elem - ,state: state - ,data: item + elem: elem, + state: state, + data: item }); }); }; @@ -344,9 +350,10 @@ layui.define('form', function(exports){ // 同步子节点选中状态 if(typeof item.children === 'object' || elem.find('.'+ELEM_PACK)[0]){ - var childs = elem.find('.'+ ELEM_PACK).find('input[same="layuiTreeCheck"]'); - childs.each(function(){ + var elemCheckboxs = elem.find('.'+ ELEM_PACK).find('input[same="layuiTreeCheck"]'); + elemCheckboxs.each(function(index){ if(this.disabled) return; // 不可点击则跳过 + if(item.children[index]) item.children[index]['checked'] = checked; this.checked = checked; }); }; @@ -403,6 +410,7 @@ layui.define('form', function(exports){ if(elemCheckbox.prop('disabled')) return; that.setCheckbox(elem, item, elemCheckbox); + item.checked = checked; // 复选框点击产生的回调 options.oncheck && options.oncheck({ @@ -747,9 +755,10 @@ layui.define('form', function(exports){ layui.each(data, function(index, item){ layui.each(checkId, function(index2, item2){ if(item.id == item2){ + item['checked'] = true; var cloneItem = $.extend({}, item); delete cloneItem.children; - + checkNode.push(cloneItem); if(item.children){