layui tree实现获取子节点所有值的实例代码,具体代码如下:layui tree实现获取子节点所有值的实例代码,具体代码如下: layui.use(['tree', 'form'], function(){ var tree = layui.tree; var form = layui.form; // 模拟数据 var data = [ { name: '节点1', id: 1, children: [ {name: '节点1-1', id: 11, children: [{name: '节点1-1-1', id: 111}]}, {name: '节点1-2
layui.use(['tree', 'form'], function(){
var tree = layui.tree;
var form = layui.form;
// 模拟数据
var data = [
{
name: '节点1',
id: 1,
children: [
{name: '节点1-1', id: 11, children: [{name: '节点1-1-1', id: 111}]},
{name: '节点1-2', id: 12}
]
}
// ... 其他节点数据
];
// 初始化树
tree.render({
elem: '#test' // 绑定元素
,data: data
,showCheckbox: true // 显示复选框
,id: 'id' // 设置节点id的属性名
,oncheck: function(obj){
var childIds = getAllChildIds(obj.data, []);
console.log(childIds);
}
});
// 递归获取所有子节点的ID
function getAllChildIds(node, ids) {
if (node.children && node.children.length > 0) {
node.children.forEach(function(child) {
ids.push(child.id);
getAllChildIds(child, ids);
});
}
return ids;
}
});
织梦狗教程
本文标题为:layui tree实现获取子节点所有值的实例代码


基础教程推荐
猜你喜欢
- Bootstrap .has-success类 1970-01-01
- Bootstrap .img-thumbnail类 1970-01-01
- Bootstrap选择控件 1970-01-01
- Bootstrap内联表单 1970-01-01
- 带有属性的Bootstrap Tooltip插件 1970-01-01
- Bootstrap .alert类 1970-01-01
- Bootstrap可折叠 1970-01-01
- Bootstrap table-hover类 1970-01-01
- Bootstrap按钮 1970-01-01
- Bootstrap网格中型大型设备 1970-01-01