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#"
                }
            ]
        }
    ]
    
    

     
  • 相关阅读:
    洛谷 1012 拼数(NOIp1998提高组)
    洛谷 1540 机器翻译
    洛谷 1328 生活大爆炸版石头剪刀布(NOIp2014提高组)
    洛谷 2820 局域网
    洛谷 1359 租用游艇
    洛谷 1195 口袋的天空
    洛谷 1316 丢瓶盖
    洛谷 1258 小车问题
    洛谷 1017 进制转换 (NOIp2000提高组T1)
    GYM
  • 原文地址:https://www.cnblogs.com/richy/p/3197929.html
Copyright © 2011-2022 走看看