public string GetTreeNav(int ID,int Num) { StringBuilder sb = new StringBuilder(); sb.Append("[{"id":1,"text":"根目录","children":["); sb.Append(GetTreeSon(ID,Num)); sb.Append("]}]"); return sb.ToString(); } public string GetTreeSon(int ID,int Num) { StringBuilder sb = new StringBuilder(); DataTable dt = GetTableByParentID(ID,"视频"); for (int i = 0; i < dt.Rows.Count; i++) { if (Num == 1) { sb.Append("{"id":" + dt.Rows[i]["ID"].ToString() + ","text":"" + dt.Rows[i]["ClassName"].ToString() + ""}"); } else { sb.Append("{"id":" + dt.Rows[i]["ID"].ToString() + ","text":"" + dt.Rows[i]["ClassName"].ToString() + "","state":"closed","children":[" + GetTreeSon(Convert.ToInt32(dt.Rows[i]["ID"]), Num - 1) + "]}"); } if (i < dt.Rows.Count - 1) { sb.Append(","); } } return sb.ToString(); }