您当前的位置: 首页 > 

Charge8

暂无认证

  • 2浏览

    0关注

    447博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

jsTree自定义contextmenu

Charge8 发布时间:2019-03-26 15:50:15 ,浏览量:2

比如不希望用jstree自身的contextmenu,希望自己定义。则代码如下:


function reloadTree(){

    dialog.hide();

    jQuery("#"+treeid).jstree("refresh");

}

function showTree(id,json){

    treeid = id;

    menuTree = jQuery("#"+id).jstree({

        "core" : {

        "data":{

            "url":"/accountmanage/getMenuData",

            "dataType":"json",

            "cache":false

        }

      },

      "types" : {

        "default" : {

          "valid_children" : ["default","file"]

        },

        "file" : {

          "icon" : "glyphicon glyphicon-file",

          "valid_children" : []

        }

      },

      "plugins" : [

        "contextmenu", "dnd", "search",

        "state", "types", "wholerow"

      ],

      "contextmenu":{

        "items":{

            "create":null,

            "rename":null,

            "remove":null,

            "ccp":null,

            "新建菜单":{

                "label":"新建菜单",

                "action":function(data){

                    var inst = jQuery.jstree.reference(data.reference),

                    obj = inst.get_node(data.reference);

                    dialog.show({"title":"新建“"+obj.text+"”的子菜单",url:"/accountmanage/createMenu?id="+obj.id,height:280,width:400});

                }

            },

            "删除菜单":{

                "label":"删除菜单",

                "action":function(data){

                    var inst = jQuery.jstree.reference(data.reference),

                    obj = inst.get_node(data.reference);

                    if(confirm("确定要删除此菜单?删除后不可恢复。")){

                        jQuery.get("/accountmanage/deleteMenu?id="+obj.id,function(dat){

                            if(dat == 1){

                                alert("删除菜单成功!");

                                jQuery("#"+treeid).jstree("refresh");

                            }else{

                                alert("删除菜单失败!");

                            }

                        });

                    }

                }

            },

            "编辑菜单":{

                "label":"编辑菜单",

                "action":function(data){

                    var inst = jQuery.jstree.reference(data.reference),

                    obj = inst.get_node(data.reference);

                    dialog.show({"title":"编辑“"+obj.text+"”菜单",url:"/accountmanage/editMenu?id="+obj.id,height:280,width:400});

                }

            }

        }

      }

    });

    //after show menutree complete, adjust the td height

    jQuery("#"+id).parents("td").height((jQuery("#"+id).height()+"50")+"px");

}

转载于:https://blog.csdn.net/rongyongfeikai2/article/details/46691173

关注
打赏
1664721914
查看更多评论
立即登录/注册

微信扫码登录

0.0408s