layui.use(['form', 'layedit', 'laydate','tree','util'], function() { var form = layui.form, layer = layui.layer, tree = layui.tree, util = layui.util; //开启复选框 tree.render({ elem: '#test7' ,data: getData() ,showCheckbox: true ,id: 'id' // ,oncheck: function(obj){ // console.log(obj.data); //得到当前点击的节点数据 // console.log(obj.checked); //得到当前节点的展开状态:open、close、normal // console.log(obj.elem); //得到当前节点元素 // } }); //监听提交 form.on('submit(form_commit)', function(data) { //获得选中的节点 var checkData = tree.getChecked('id'); var list = new Array(); list = getChecked_list(checkData); console.log(checkData) console.log(list); }); // 获取选中节点的id function getChecked_list(data) { var id = ""; $.each(data, function (index, item) { if (id != "") { id = id + "," + item.id; } else { id = item.id; } var i = getChecked_list(item.children); if (i != "") { id = id + "," + i; } }); return id; } });