mirror of https://github.com/layui/layui
优化 tree 的 `checked,spread` 属性赋值机制
parent
c27ae1bf4f
commit
4749883746
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue