44 lines
1.1 KiB
HTML
44 lines
1.1 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>树组件</title>
|
|
|
|
</head>
|
|
<body>
|
|
<div id="test1"></div>
|
|
|
|
<script>
|
|
layui.use('tree', function(){
|
|
var tree = layui.tree;
|
|
|
|
//渲染
|
|
var inst1 = tree.render({
|
|
elem: '#test1' //绑定元素
|
|
,data: [{
|
|
"title": "一级1","id": 1,"field": "name1","checked": true,"spread": true,"children": [
|
|
{ "title": "二级1-3","id": 10 ,"field": ""}
|
|
]
|
|
},{
|
|
"title": "一级2","id": 2,"field": "name1","checked": true,"spread": true,"children": [
|
|
{ "title": "二级2-3","id": 20 ,"field": ""}
|
|
]
|
|
},{
|
|
"title": "一级3","id": 2,"field": "name1","checked": true,"spread": true,"children": [
|
|
{"title": "二级3-3",
|
|
"id": 30,
|
|
"field": ""}
|
|
]
|
|
}
|
|
]
|
|
,showCheckbox: true //是否显示复选框
|
|
,id: 'demoId' //定义索引
|
|
});
|
|
|
|
var checkData = tree.getChecked('demoId');
|
|
console.log(checkData);
|
|
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |