jstree插件的使用(进阶)——动态json数据创建树

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <!-- jstree css样式 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/default/style.min.css" />
</head>
<body>
    <!-- 设置容器元素 -->
    <div id="jstree"></div>
    <!-- jquery.js -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
    <!-- jstree js核心文件 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js"></script>
    <script type="text/javascript">
        $(function(){ 
            //当DOM准备好时创建一个jstree实例
            $('#jstree').jstree({
                //core 存储核心的所有默认值
                'core' : {
                    //data 数据配置:在这里可以传递HTML字符串或JSON数组
                    'data' : [
                        {
                            'id' : 'ajson1',
                            'parent' : '#',//  #  根目录
                            'icon' : 'jstree-folder',//jstree-folder 文件夹图标(默认图标)
                            'text':'部门',
                            "state" :{
                                "opened" : true //默认打开文件夹
                            }
                        },
                        {
                            'id': 'ajson2',
                            'parent' : 'ajson1',
                            'text':'纪检部'
                        },
                        {
                            'id': 'ajson3',
                            'parent' : 'ajson1',
                            'text':'卫生部'
                        },
                        {
                            'id': 'ajson4',
                            'parent' : 'ajson1',
                            'text':'公寓部'
                        },
                        {
                            'id': 'ajson5',
                            'parent' : 'ajson1',
                            'text':'女生部'
                        },
                        {
                            'id': 'ajson6',
                            'parent' : 'ajson2',
                            'icon' : 'jstree-file',//jstree-file 文件图标
                            'text':'张三'
                        },
                        {
                            'id': 'ajson7',
                            'parent' : 'ajson2',
                            'icon' : 'jstree-file',
                            'text':'李四'
                        },
                        {
                            'id': 'ajson8',
                            'parent' : 'ajson2',
                            'icon' : 'jstree-file',
                            'text':'王五'
                        }
                    ]
                }
            }); 
        });
    </script>
</body>
</html>

效果图

转载于:https://www.cnblogs.com/xiaohualu/p/9835516.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值