jstree自定义contextmenu

比如不希望用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");
}


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值