From c27ae1bf4fb077455e48fe95c1c02dd581a7321b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B4=A4=E5=BF=83?= <3277200+sentsim@users.noreply.github.com> Date: Mon, 31 Jul 2023 12:33:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20tree=20=E7=9A=84=20`checke?= =?UTF-8?q?d`=20=E5=B1=9E=E6=80=A7=E8=B5=8B=E5=80=BC=E6=9C=BA=E5=88=B6?= =?UTF-8?q?=EF=BC=8C=E8=8B=A5=E5=88=9D=E5=A7=8B=E6=95=B0=E6=8D=AE=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E8=AF=A5=E5=B1=9E=E6=80=A7=E6=97=B6=EF=BC=8C=E6=89=8D?= =?UTF-8?q?=E5=AF=B9=E5=85=B6=E8=BF=9B=E8=A1=8C=E5=8A=A8=E6=80=81=E8=B5=8B?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/tree.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/modules/tree.js b/src/modules/tree.js index 4fc94a4b..646bb1b7 100644 --- a/src/modules/tree.js +++ b/src/modules/tree.js @@ -328,7 +328,7 @@ layui.define('form', function(exports){ // 获取选中状态 if(elemCheckbox[0]){ - item['checked'] = elemCheckbox.prop('checked'); + that.setCheckValue(item, elemCheckbox.prop('checked')); } // 点击产生的回调 @@ -339,6 +339,13 @@ layui.define('form', function(exports){ }); }); }; + + // 设置数据源 checked 字段值 + Class.prototype.setCheckValue = function(obj, checked){ + if('checked' in obj){ + obj.checked = checked; + } + }; // 计算复选框选中状态 Class.prototype.setCheckbox = function(elem, item, elemCheckbox){ @@ -353,8 +360,9 @@ layui.define('form', function(exports){ 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; + var children = item.children[index]; + if(children) that.setCheckValue(children, checked); + that.setCheckValue(this, checked); }); }; @@ -410,7 +418,7 @@ layui.define('form', function(exports){ if(elemCheckbox.prop('disabled')) return; that.setCheckbox(elem, item, elemCheckbox); - item.checked = checked; + that.setCheckValue(item, checked); // 复选框点击产生的回调 options.oncheck && options.oncheck({ @@ -755,7 +763,8 @@ layui.define('form', function(exports){ layui.each(data, function(index, item){ layui.each(checkId, function(index2, item2){ if(item.id == item2){ - item['checked'] = true; + that.setCheckValue(item, true); + var cloneItem = $.extend({}, item); delete cloneItem.children;