Browse Source

修复 tree 点击复选框时未将对应的数据中的 `checked` 属性值进行同步的问题

pull/1307/head
贤心 1 year ago
parent
commit
9359023af4
  1. 21
      src/modules/tree.js

21
src/modules/tree.js

@ -277,6 +277,7 @@ layui.define('form', function(exports){
var options = that.config; var options = that.config;
var entry = elem.children('.'+ELEM_ENTRY); var entry = elem.children('.'+ELEM_ENTRY);
var elemMain = entry.children('.'+ ELEM_MAIN); var elemMain = entry.children('.'+ ELEM_MAIN);
var elemCheckbox = elemMain.find('input[same="layuiTreeCheck"]');
var elemIcon = entry.find('.'+ ICON_CLICK); var elemIcon = entry.find('.'+ ICON_CLICK);
var elemText = entry.find('.'+ ELEM_TEXT); var elemText = entry.find('.'+ ELEM_TEXT);
var touchOpen = options.onlyIconControl ? elemIcon : elemMain; // 判断展开通过节点还是箭头图标 var touchOpen = options.onlyIconControl ? elemIcon : elemMain; // 判断展开通过节点还是箭头图标
@ -324,12 +325,17 @@ layui.define('form', function(exports){
} else { } else {
state = options.onlyIconControl ? 'close' : 'open'; state = options.onlyIconControl ? 'close' : 'open';
} }
// 获取选中状态
if(elemCheckbox[0]){
item['checked'] = elemCheckbox.prop('checked');
}
// 点击产生的回调 // 点击产生的回调
options.click && options.click({ options.click && options.click({
elem: elem elem: elem,
,state: state state: state,
,data: item data: item
}); });
}); });
}; };
@ -344,9 +350,10 @@ layui.define('form', function(exports){
// 同步子节点选中状态 // 同步子节点选中状态
if(typeof item.children === 'object' || elem.find('.'+ELEM_PACK)[0]){ if(typeof item.children === 'object' || elem.find('.'+ELEM_PACK)[0]){
var childs = elem.find('.'+ ELEM_PACK).find('input[same="layuiTreeCheck"]'); var elemCheckboxs = elem.find('.'+ ELEM_PACK).find('input[same="layuiTreeCheck"]');
childs.each(function(){ elemCheckboxs.each(function(index){
if(this.disabled) return; // 不可点击则跳过 if(this.disabled) return; // 不可点击则跳过
if(item.children[index]) item.children[index]['checked'] = checked;
this.checked = checked; this.checked = checked;
}); });
}; };
@ -403,6 +410,7 @@ layui.define('form', function(exports){
if(elemCheckbox.prop('disabled')) return; if(elemCheckbox.prop('disabled')) return;
that.setCheckbox(elem, item, elemCheckbox); that.setCheckbox(elem, item, elemCheckbox);
item.checked = checked;
// 复选框点击产生的回调 // 复选框点击产生的回调
options.oncheck && options.oncheck({ options.oncheck && options.oncheck({
@ -747,9 +755,10 @@ layui.define('form', function(exports){
layui.each(data, function(index, item){ layui.each(data, function(index, item){
layui.each(checkId, function(index2, item2){ layui.each(checkId, function(index2, item2){
if(item.id == item2){ if(item.id == item2){
item['checked'] = true;
var cloneItem = $.extend({}, item); var cloneItem = $.extend({}, item);
delete cloneItem.children; delete cloneItem.children;
checkNode.push(cloneItem); checkNode.push(cloneItem);
if(item.children){ if(item.children){

Loading…
Cancel
Save