mirror of https://github.com/layui/layui
fix(atree): 2.0.0-beta
parent
a34c39a1dd
commit
ea24b7635d
|
@ -33,6 +33,8 @@
|
||||||
// drag: true,
|
// drag: true,
|
||||||
spreadAll:true,
|
spreadAll:true,
|
||||||
props:{
|
props:{
|
||||||
|
addBtnLabel:'新增',
|
||||||
|
deleteBtnLabel:'删除',
|
||||||
name: 'name',
|
name: 'name',
|
||||||
id: 'id',
|
id: 'id',
|
||||||
children:'children',
|
children:'children',
|
||||||
|
|
|
@ -19,7 +19,9 @@ layui.define('jquery', function(exports) {
|
||||||
id: 'id',
|
id: 'id',
|
||||||
children: 'children',
|
children: 'children',
|
||||||
checkbox: 'checkbox',
|
checkbox: 'checkbox',
|
||||||
spread:'spread'
|
spread: 'spread',
|
||||||
|
deleteBtnLabelKey: 'delete',
|
||||||
|
addBtnLabelKey: 'add',
|
||||||
};
|
};
|
||||||
|
|
||||||
var enterSkin = 'layui-tree-enter',
|
var enterSkin = 'layui-tree-enter',
|
||||||
|
@ -32,6 +34,8 @@ layui.define('jquery', function(exports) {
|
||||||
this.childrenKey = this.props.children || props.children;
|
this.childrenKey = this.props.children || props.children;
|
||||||
this.checkboxKey = this.props.checkbox || props.checkbox;
|
this.checkboxKey = this.props.checkbox || props.checkbox;
|
||||||
this.spreadKey = this.props.spread || props.spread;
|
this.spreadKey = this.props.spread || props.spread;
|
||||||
|
this.addBtnLabelKey = this.props.addBtnLabel || props.addBtnLabel;
|
||||||
|
this.deleteBtnLabelKey = this.props.deleteBtnLabel || props.deleteBtnLabel;
|
||||||
};
|
};
|
||||||
//图标
|
//图标
|
||||||
var icon = {
|
var icon = {
|
||||||
|
@ -112,8 +116,8 @@ layui.define('jquery', function(exports) {
|
||||||
},
|
},
|
||||||
menu: function() {
|
menu: function() {
|
||||||
return '<div class="layui-tree-menu">' +
|
return '<div class="layui-tree-menu">' +
|
||||||
'<span class="layui-tree-add">Add</span>' +
|
'<span class="layui-tree-add">' + that.addBtnLabelKey + '</span>' +
|
||||||
'<span class="layui-tree-delete">Delete</span>' +
|
'<span class="layui-tree-delete">' + that.deleteBtnLabelKey + '</span>' +
|
||||||
'</div>'
|
'</div>'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -124,11 +128,11 @@ layui.define('jquery', function(exports) {
|
||||||
var that = this,
|
var that = this,
|
||||||
options = that.options
|
options = that.options
|
||||||
var dom = that.getDom(item);
|
var dom = that.getDom(item);
|
||||||
var li = ['<li '
|
var li = ['<li ' +
|
||||||
+ (item[that.spreadKey] || options.spreadAll ? 'data-spread="' + (item[that.spreadKey] || true) + '"' : '')
|
(item[that.spreadKey] || options.spreadAll ? 'data-spread="' + (item[that.spreadKey] || true) + '"' : '') +
|
||||||
+(item[that.checkboxKey] ? 'data-check="' + item[that.checkboxKey] + '"' : '')
|
(item[that.checkboxKey] ? 'data-check="' + item[that.checkboxKey] + '"' : '') +
|
||||||
+('data-id=' + item[that.idKey])
|
('data-id=' + item[that.idKey]) +
|
||||||
+ '><div class="layui-tree-node">'
|
'><div class="layui-tree-node">'
|
||||||
//展开箭头
|
//展开箭头
|
||||||
,
|
,
|
||||||
dom.spread()
|
dom.spread()
|
||||||
|
@ -142,8 +146,7 @@ layui.define('jquery', function(exports) {
|
||||||
dom.node()
|
dom.node()
|
||||||
//菜单
|
//菜单
|
||||||
,
|
,
|
||||||
dom.menu()
|
dom.menu(),
|
||||||
,
|
|
||||||
'</div></li>'
|
'</div></li>'
|
||||||
].join('');
|
].join('');
|
||||||
return li;
|
return li;
|
||||||
|
@ -200,7 +203,7 @@ layui.define('jquery', function(exports) {
|
||||||
}
|
}
|
||||||
if(!arrow[0]) {
|
if(!arrow[0]) {
|
||||||
arrow = $(dom.spread());
|
arrow = $(dom.spread());
|
||||||
elem.prepend(arrow);
|
node.prepend(arrow);
|
||||||
that.spread(elem, item);
|
that.spread(elem, item);
|
||||||
}
|
}
|
||||||
if(!elem.data('spread')) {
|
if(!elem.data('spread')) {
|
||||||
|
@ -260,22 +263,44 @@ layui.define('jquery', function(exports) {
|
||||||
var checkbox = node.children('.layui-tree-check')
|
var checkbox = node.children('.layui-tree-check')
|
||||||
var ul = elem.children('ul'),
|
var ul = elem.children('ul'),
|
||||||
a = node.children('a');
|
a = node.children('a');
|
||||||
var check = function() {
|
var whileAllCheck = function(dom, item, type) {
|
||||||
var index = layui.findObj(changeList, item);
|
var list = dom.children('.layui-show').find('li');
|
||||||
if(elem.data('check')) {
|
var children = item ? item.children || [] : [];
|
||||||
elem.data('check', null)
|
for(var i = 0; i < list.length; i++) {
|
||||||
checkbox.removeClass(' is-checked');
|
var li = $(list[i]);
|
||||||
checkbox.html(icon.checkbox[0]);
|
setCheck(li, children[i], type);
|
||||||
} else {
|
whileAllCheck(li, children[i], type);
|
||||||
elem.data('check', true);
|
|
||||||
checkbox.addClass(' is-checked');
|
|
||||||
checkbox.html(icon.checkbox[1]);
|
|
||||||
}
|
}
|
||||||
if(index === -1) {
|
}
|
||||||
changeList.push(item);
|
var setCheck = function(elem, item, type) {
|
||||||
|
var checkbox = elem.children('.layui-tree-node').find('.layui-tree-check');
|
||||||
|
if(type) {
|
||||||
|
elem.data('check', true)
|
||||||
|
checkbox.html(icon.checkbox[1])
|
||||||
|
checkbox.addClass(' is-checked');
|
||||||
} else {
|
} else {
|
||||||
|
elem.data('check', null);
|
||||||
|
checkbox.removeClass(' is-checked');
|
||||||
|
checkbox.html(icon.checkbox[0])
|
||||||
|
}
|
||||||
|
if(item) {
|
||||||
|
var index = layui.findObj(changeList, item[that.idKey], that.idKey);
|
||||||
|
if(index === -1 && type === true) {
|
||||||
|
changeList.push(item);
|
||||||
|
} else if(type === false) {
|
||||||
changeList.splice(index, 1);
|
changeList.splice(index, 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var check = function() {
|
||||||
|
var checkFlag;
|
||||||
|
if(elem.data('check')) {
|
||||||
|
checkFlag = false;
|
||||||
|
} else {
|
||||||
|
checkFlag = true;
|
||||||
|
}
|
||||||
|
setCheck(elem, item, checkFlag)
|
||||||
|
whileAllCheck(elem, item, checkFlag);
|
||||||
that.change();
|
that.change();
|
||||||
}
|
}
|
||||||
checkbox.on('click', check);
|
checkbox.on('click', check);
|
||||||
|
|
|
@ -437,11 +437,11 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
//寻找对象是否存在数组中
|
//寻找对象是否存在数组中
|
||||||
Layui.prototype.findObj = function(list,obj) {
|
Layui.prototype.findObj = function(list,value,key) {
|
||||||
var that = this,
|
var that = this,
|
||||||
result = -1;
|
result = -1;
|
||||||
that.each(list, function(index, item) {
|
that.each(list, function(index, item) {
|
||||||
if(that.isEqualObj(obj,item))result = index;
|
if(item[key] == value)result = index;
|
||||||
})
|
})
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue