layui.use('tree', function () {
var tree = layui.tree;
//渲染
stree = tree.render({
elem: '#demo2' //绑定元素
, data: treeService
, showCheckbox: true
, click: function (obj) { //节点选中状态改变事件监听,全选框有自己的监听事件
console.log(obj);
var nodes = document.getElementsByClassName("layui-tree-txt");
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].innerHTML === obj.data.title) { // if(obj.data.children){} //判断当前节点是否有子节点
if (obj.data.children == null || obj.data.children.length == 0) {//判断是不是子节点(父节点对应的children不为空,且有的父节点长度为0也可代表子节点)
nodes[i].style.color = "#555";//灰色
nodes[i].checked = true;
//将选中的值存储在Session
} else {
nodes[i].style.color = "#555";//灰色
}
} else {
nodes[i].style.color = "#555";//灰色
}
}
}
});
});