zoukankan      html  css  js  c++  java
  • 无极树(待整理)

    public  string GetUserPermissonJson(string userID)
        {
            UserPermissionQuery upq = new UserPermissionQuery(Common.DbHelper_OA);
            DataTable dt = upq.ReturnFunction(int.Parse(userID));
            List<TreeNodeM> t = new List<TreeNodeM>();
            BindTreeNode(0, t,dt);
            string json = JsonConvert.SerializeObject(t);
            json = json.Replace(","children":[]","");
            json = json.Replace("check", "checked");
            return json;
        }
    
        public void BindTreeNode(int parentID,List<TreeNodeM> tnm,DataTable dt) {
            
            DataView dv = new DataView(dt);
            dv.RowFilter = "Parent_ID=" + parentID;
            foreach (DataRowView dr in dv){
                TreeNodeM t = new TreeNodeM()
                {
                    id = Int32.Parse(dr["ID"].ToString()),
                    text = dr["Permission_Name"].ToString(),
                    check = dr["Permission_Val"].ToString() == "1" ? true : false,
                    children = new List<TreeNodeM>()
                };
                tnm.Add(t);
                BindTreeNode(Int32.Parse(dr["ID"].ToString()),t.children,dt);
                
            }
    
        }
     public class TreeNodeM
        {
            //节点编号
            public int id;
            // 节点内容
            public String text;
            ////父节点编号
            //public int parentId;
            public bool check;
            ////是否为叶子节点(即没有子节点)
            //private bool leaf;
            //子节点列表
            public List<TreeNodeM> children;
        }
    [
        {
            "id": 1,
            "text": "Folder1",
            "iconCls": "icon-save",
            "children": [
                {
                    "text": "File1",
                    "checked": true
                },
                {
                    "text": "Books",
                    "state": "open",
                    "attributes": {
                        "url": "/demo/book/abc",
                        "price": 100
                    },
                    "children": [
                        {
                            "text": "PhotoShop",
                            "checked": true
                        },
                        {
                            "id": 8,
                            "text": "Sub Bookds",
                            "state": "closed"
                        }
                    ]
                }
            ]
        },
        {
            "text": "Languages",
            "state": "closed",
            "children": [
                {
                    "text": "Java"
                },
                {
                    "text": "C#"
                }
            ]
        }
    ]
    
    

     
  • 相关阅读:
    24. Swap Nodes in Pairs
    23. Merge k Sorted Lists
    shell脚本报错:"[: =: unary operator expected"
    一种用 数组元素 指定 所调函数 的方法
    阻塞 非阻塞
    Linux open() 一个函数,两个函数原型
    QT 执行windows cmd 命令并读取结果
    Qt5 escape spaces in path
    获取磁盘的 总容量,空余容量,已用容量 【windows】
    通过进程名称,获取其路径
  • 原文地址:https://www.cnblogs.com/richy/p/3197929.html
Copyright © 2011-2022 走看看