BootStrap Jstree 树形菜单的增删改查的实现源码

本文介绍了如何利用BootStrap Jstree插件实现树形菜单的增删改查功能。首先,下载并引入jstree的JS和CSS文件,接着初始化插件,配置json_data和plugins参数。contextmenu参数允许在树形节点上显示右键菜单,提供增删改查操作。json数据结构用于动态加载菜单,通过递归方式组装无限级菜单。创建节点时,可以通过右键菜单触发AJAX请求,将新节点保存到数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.首先需下载jstree的插件点击打开链接

2.在页面引入插件js文件css文件

<link rel="stylesheet" href="plugins/jstree/themes/classic/style.css">
<script type="text/javascript" src="plugins/jstree/_lib/jquery.js"></script>
<script type="text/javascript"
	src="plugins/jstree/_lib/jquery.cookie.js"></script>
<script type="text/javascript"
	src="plugins/jstree/_lib/jquery.hotkeys.js"></script>
<script type="text/javascript" src="plugins/jstree/jquery.jstree.js"></script>

3.初始化控件

 1)html

<div id="demo2" class="demo" style="height:100px;"></div>

2)js 使用 demo2来初始化树形控件

<script type="text/javascript" class="source below">
    $(function() {
        $("#demo2").jstree(
            {
                "json_data" : {
                    "ajax" : {
                        "url" : "http://localhost:8080/MemberManager/DepartmentTreeJson",
                        "data" : function(n) {
                                    // the result is fed to the AJAX request `data` option
                                    return {
                                        "operation" : "get_children",
                                        "id" : n.attr ? n
                                            .attr(
                                            "id")
                                            .replace(
                                            "node_",
                                            "")
                                            : 1
                                    };
                                }
                            }
                        },

                "plugins" : [
                            "themes",
                            "json_data",

                            "ui",
                            "crrm",
                            "contextmenu",

                            "search" ],

                    })

            .bind("loaded.jstree",
                    function(event, data) {
                    })

            .bind(
                    "select_node.jstree",
                    function(event, data) {
                        if (data.rslt.obj
                                .attr("id") != undefined) {
                        }
                    })
            .bind(
                    "remove.jstree",
                    function(e, data) {
                        data.rslt.obj.each(function() {
                                $.ajax({
                                        async : false,
                                        type : 'POST',
                                        url : "http://localhost:8080/MemberManager/CreateNodeForDepartment",
                                        data : {
                                            "operation" : "remove_node",
                                            "id" : this.id.replace("node_", "")
                                        },
                                        success : function(r) {
                                            if (!r.status) {
                                                data.inst.refresh();
                                            }
                                        }
                                    });
                            });
                    })
            .bind(
                    "remove.jstree",
                    function(e, data) {
                        data.rslt.obj.each(function() {
                                $.ajax({
                                        async : false,
                                        type : 'POST',
                                        url : "http://localhost:8080/MemberManager/CreateNodeForDepartment",
                                        data : {
                                            "operation" : "remove_node",
                                            "id" : this.id
                                                .replace(
                                                "node_",
                                                "")
                           
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值