From 47498837466f98172cbcc61f833d1c8bd4a36577 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 15:43:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20tree=20=E7=9A=84=20`checke?= =?UTF-8?q?d,spread`=20=E5=B1=9E=E6=80=A7=E8=B5=8B=E5=80=BC=E6=9C=BA?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/tree.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/modules/tree.js b/src/modules/tree.js index 646bb1b7..996ae4d7 100644 --- a/src/modules/tree.js +++ b/src/modules/tree.js @@ -296,10 +296,12 @@ layui.define('form', function(exports){ elem.removeClass(ELEM_SPREAD); packCont.slideUp(200); iconClick.removeClass(ICON_SUB).addClass(ICON_ADD); + that.updateFieldValue(item, 'spread', false); }else{ elem.addClass(ELEM_SPREAD); packCont.slideDown(200); iconClick.addClass(ICON_SUB).removeClass(ICON_ADD); + that.updateFieldValue(item, 'spread', true); // 是否手风琴 if(options.accordion){ @@ -328,7 +330,7 @@ layui.define('form', function(exports){ // 获取选中状态 if(elemCheckbox[0]){ - that.setCheckValue(item, elemCheckbox.prop('checked')); + that.updateFieldValue(item, 'checked', elemCheckbox.prop('checked')); } // 点击产生的回调 @@ -340,11 +342,9 @@ layui.define('form', function(exports){ }); }; - // 设置数据源 checked 字段值 - Class.prototype.setCheckValue = function(obj, checked){ - if('checked' in obj){ - obj.checked = checked; - } + // 更新数据源 checked,spread 字段值 + Class.prototype.updateFieldValue = function(obj, field, value){ + if(field in obj) obj[field] = value; }; // 计算复选框选中状态 @@ -361,8 +361,8 @@ layui.define('form', function(exports){ elemCheckboxs.each(function(index){ if(this.disabled) return; // 不可点击则跳过 var children = item.children[index]; - if(children) that.setCheckValue(children, checked); - that.setCheckValue(this, checked); + if(children) that.updateFieldValue(children, 'checked', checked); + that.updateFieldValue(this, 'checked', checked); }); }; @@ -418,7 +418,7 @@ layui.define('form', function(exports){ if(elemCheckbox.prop('disabled')) return; that.setCheckbox(elem, item, elemCheckbox); - that.setCheckValue(item, checked); + that.updateFieldValue(item, 'checked', checked); // 复选框点击产生的回调 options.oncheck && options.oncheck({ @@ -763,7 +763,7 @@ layui.define('form', function(exports){ layui.each(data, function(index, item){ layui.each(checkId, function(index2, item2){ if(item.id == item2){ - that.setCheckValue(item, true); + that.updateFieldValue(item, 'checked', true); var cloneItem = $.extend({}, item); delete cloneItem.children;