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