IListToJson 泛型集合转化为Jsontree

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 using MapUni.Server.MobileEnforcement.BLL.Managers;
 8 using MapUni.MobileEnforcement.DAL.Models;
 9 
10 public partial class TaskExecute_test : System.Web.UI.Page
11 {
12     protected void Page_Load(object sender, EventArgs e)
13     {      
14          if(!IsPostBack)
15          {
16              string json = GetjosStr();
17              Response.Write(json);
18          }
19     }
       //添加子节点方法
20
public List<T_YDZF_RWLX> addNode(List<T_YDZF_RWLX> list) 21 { 22 List<T_YDZF_RWLX> treenode = new List<T_YDZF_RWLX>(); 23 foreach( T_YDZF_RWLX r in list ) 24 { 25 T_YDZF_RWLX tnode = new T_YDZF_RWLX(); 26 tnode.Code = r.Code; 27 tnode.Name = r.Name; 28 tnode.PCode = r.PCode; 29 List<T_YDZF_RWLX> listchidren = TempletTypeManager.GetTempletTypesByPCode(r.Code).ToList<T_YDZF_RWLX>(); 30 tnode.Children = addNode(listchidren); 31 treenode.Add(tnode); 32 } 33 return treenode; 34 } //递归获取json tree 方法
35
public string GetjosStr() 36 { //找到根级节点下的所有节点
37
List<T_YDZF_RWLX> prenode = TempletTypeManager.GetTempletTypesByPCode("0000").ToList<T_YDZF_RWLX>(); 38 List<T_YDZF_RWLX> PreTree = new List<T_YDZF_RWLX>(); 39 T_YDZF_RWLX rwlx = new T_YDZF_RWLX(); 40 rwlx.Code = "0000"; 41 rwlx.Name = "toptree"; 42 rwlx.PCode = ""; //递归添加子节点
43
rwlx.Children = addNode(prenode); 44 PreTree.Add(rwlx); 45 string json= PreTree.ToJson() ; 46 return json; 47 } 48 }

 

posted @ 2013-06-28 16:51  ` W@y、  阅读(9209)  评论(0编辑  收藏  举报