layui树形组件获取选中id

时间:2025-04-02 16:24:16
//基本演示 tree.render({ elem: '#test12' ,data: data //具体data格式看官方文档 ,showCheckbox: true //是否显示复选框 ,id: 'demoId1' ,isJump: true //是否允许点击节点时弹出新窗口跳转 ,click: function(obj){ var data = obj.data; //获取当前点击的节点数据 layer.msg('状态:'+ obj.state + '<br>节点数据:' + JSON.stringify(data)); } }); var checkData = tree.getChecked('demoId1'); var list = new Array(); list = getChecked_list(checkData); console.log(checkData) console.log(list); 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; }