分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

jstree使用示例代码

发布时间:2023-09-06 02:23责任编辑:胡小海关键词:js
首先定义一个展示树的div
<div id="twDept" class="tree-demo"></div>
 
  //初始化树
        function initTree() {
            $(‘#twDept‘).jstree({
                "core": {
                    "themes": {
                        "responsive": false
                    },
                    ‘check_callback‘: true,
                    ‘data‘: function (obj, callback) {
                        report.DataGet(‘查询1级部门的接口路径‘, null, function (data) {
                            if (data) {
                                callback.call(this, data);
                            }
                        }, null, ‘json‘);
                    }
                },
                "types": {
                    "default": {
                        "icon": "fa fa-folder icon-state-warning icon-lg"
                    },
                    "file": {
                        "icon": "fa fa-file icon-state-warning icon-lg"
                    }
                },
                "plugins": ["types", "checkbox"],
                "checkbox": {
                    "keep_selected_style": false,//是否默认选中
                    "three_state": false//父子级别级联选择
                }
            });
            $(‘#twDept‘).on("loaded.jstree", function (e, data) {
                var root = e.target.firstChild.firstChild;
                data.instance.open_node(root);
                _inst = data.instance;
            });
            $(‘#twDept‘).on("open_node.jstree", function (e, data) {
                var inst = data.instance;
                var selectedNode = inst.get_node(data.node);
                var firChild = $(‘#twDept‘).jstree("get_node", inst.get_children_dom(selectedNode)[0].id);
                if (firChild.text == "" && selectedNode.id != e.target.firstChild.firstChild.id) {
                    selectedNode.children = [];
                    report.DataGet(‘查询子节点的接口路径‘?code=‘ + selectedNode.li_attr.treeDeptCode, null, function (data) {
                        if (data) {
                            $.each(data, function (i, item) {
                                inst.create_node(selectedNode, item, "last");
                            })
                        }
                    }, null, ‘json‘);
                }
            });
            //end new
        }

jstree使用示例代码

原文地址:https://www.cnblogs.com/nayilvyangguang/p/9981518.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved