html代码部分:
<div id="menuTree" class="demo-tree-more"></div>
js组件渲染代码
tree.render({
elem: '#menuTree',
data: getData(), //ajax获取data数据
showCheckbox: true, //是否显示复选
id: 'demoId'
});
点击全部展开和全部折叠按钮事件
//menuTree换成你自己的id就行
var treeContainer = document.querySelector('#menuTree');
var expandIcons = treeContainer.querySelectorAll('.layui-icon-addition'); //展开代码
var expandIcons = treeContainer.querySelectorAll('.layui-icon-subtraction'); //折叠代码
expandIcons.forEach(function(icon) {
var clickEvent = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': true
});
icon.dispatchEvent(clickEvent);
});