您的位置:首页 > 其它

无极树(待整理)

2013-07-18 11:54 46 查看
publicstringGetUserPermissonJson(stringuserID)
{
UserPermissionQueryupq=newUserPermissionQuery(Common.DbHelper_OA);
DataTabledt=upq.ReturnFunction(int.Parse(userID));
List<TreeNodeM>t=newList<TreeNodeM>();
BindTreeNode(0,t,dt);
stringjson=JsonConvert.SerializeObject(t);
json=json.Replace(",\"children\":[]","");
json=json.Replace("check","checked");
returnjson;
}

publicvoidBindTreeNode(intparentID,List<TreeNodeM>tnm,DataTabledt){

DataViewdv=newDataView(dt);
dv.RowFilter="Parent_ID="+parentID;
foreach(DataRowViewdrindv){
TreeNodeMt=newTreeNodeM()
{
id=Int32.Parse(dr["ID"].ToString()),
text=dr["Permission_Name"].ToString(),
check=dr["Permission_Val"].ToString()=="1"?true:false,
children=newList<TreeNodeM>()
};
tnm.Add(t);
BindTreeNode(Int32.Parse(dr["ID"].ToString()),t.children,dt);

}

}


publicclassTreeNodeM
{
//节点编号
publicintid;
//节点内容
publicStringtext;
////父节点编号
//publicintparentId;
publicboolcheck;
////是否为叶子节点(即没有子节点)
//privateboolleaf;
//子节点列表
publicList<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":"SubBookds",
"state":"closed"
}
]
}
]
},
{
"text":"Languages",
"state":"closed",
"children":[
{
"text":"Java"
},
{
"text":"C#"
}
]
}
]





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: