• jstree 使用


    1,角色权限

    2.

        <link href="../Scripts/jsTree/themes/default/style.css" rel="stylesheet" type="text/css" />
        <script src="../Scripts/jsTree/jquery-1.6.min.js" type="text/javascript"></script>
        <script src="../Scripts/jsTree/jquery.jstree.js" type="text/javascript"></script>
        <script type="text/javascript">
            var selectRole;//当前点选的角色
            $(function () {
                    $("#roleTree").jstree({
                        "core" : { "initially_open" : [ "topic_root" ] }, 
                        "json_data": {  "data": [<%=RoleData%>]  },
                        "themes": { "theme": "default", "dots": false, "icons": true },
                        "plugins": ["themes", "json_data", "ui"]
                    }).
                    bind("loaded.jstree", function(e,data){  data.inst.open_all(-1); }).
                    bind("select_node.jstree",  function(e,data){
                            $("#lblRole").text("");
                            if(data.rslt.obj.attr("role")){
                               $("#lblRole").html("角色["+data.rslt.obj.text()+"]")//显示
                               if(data.rslt.obj.attr("id")==selectRole)return;//重复点击自身
                               $("#moduleTree").jstree("uncheck_all");//清空
                               selectRole=data.rslt.obj.attr("id");//选中节点的ID
                               var Ids= RoleModuleMgr.GetSelectNodes(selectRole).value;
                               if(Ids)  setCheckedNode(Ids);
                            }
                        })
            });
            $(function(){
                 $("#moduleTree").jstree({
                    "json_data": {  "data": [<%=ModuleData%>]  },
                    "themes": { "theme": "default", "dots": false,"icons":false },
                    "plugins": ["themes", "json_data", "ui","checkbox"]
                }).bind("loaded.jstree",function(e,data){  data.inst.open_all(-1);})
            })
    
            // set checked node
            function setCheckedNode(ids){
                if(ids!=""){
                    var t=[];
                    var tempCheckStr=ids.split(',');
                    $(tempCheckStr).each(function(i,item){
                        t.push("#"+item);
                    })
                    $("#moduleTree").jstree("check_node",t.join(','));
                }     
            }
             // get checked node and save
            function SaveCheckedNode(){
                //非角色不允许保存
                if( $("#lblRole").text()=="") return;
    
                var ids = [];
                $("#moduleTree").jstree("get_checked",null,true).each(function(i,n){
                    ids.push(n.id);
                });
                var rtv=ids.join(',');
                if(selectRole)  {
                   var sc= RoleModuleMgr.SaveRoleModule(selectRole,rtv).value;//save rolemoduleconfig
                   if(sc)
                    $("#lblMsg").show().slideUp(3000);
                }
            } 
        </script>
    
        #region 权限 构造json 并返回
            List<ModuleInfo> lstModule = ModuleInfoBLL.ModuleInfoCmd.GetModuleInfoList(null);
            private string LoadModule(string code)
            {
                List<ModuleInfo> rst = (from m in lstModule where string.IsNullOrEmpty(code) ? (m.MCode == "001") : (m.MCode.StartsWith(code) && m.MCode.Length == code.Length + 3) select m).ToList<ModuleInfo>();
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < rst.Count; i++)
                {
                    sb.Append("{\"data\":\"" + rst[i].MName + "\",\"attr\":{\"id\":\"" + rst[i].Guid + "\"}");
                    string t = this.LoadModule(string.Format("{0}00{1}", code, i + 1));
                    if (!string.IsNullOrEmpty(t))
                        sb.AppendFormat(",\"children\":[{0}]", t);
                    if (i + 1 == rst.Count)
                        sb.Append("}");
                    else
                        sb.Append("},");
                }
                return sb.ToString();
    
            }
            #endregion
    
  • 相关阅读:
    DevExpress v17.2新版亮点—.NET Reporting篇(二)
    用MyEclipse JPA创建项目(二)
    DevExpress v17.2新版亮点—.NET Reporting篇(一)
    用MyEclipse JPA创建项目(一)
    HashMap底层实现原理
    Java 8 Tutorial
    剖析面试最常见问题之Java集合框架
    Java中String类的常用方法
    properties类以及.properties文件的使用
    递归
  • 原文地址:https://www.cnblogs.com/kingteach/p/2119125.html
Copyright © 2020-2023  润新知