private List<PortalProductListTree> selectchildren(Int64 listid, List<PortalProductList> _list) { List<PortalProductListTree> lists = new List<PortalProductListTree>(); foreach (PortalProductList item in _list) { if (item.FParentListId == listid) { PortalProductListTree newitem = new PortalProductListTree(); newitem.FProductListID = item.FProductListID; newitem.FProductListName = item.FProductListName; newitem.FProductListOrder = item.FProductListOrder; newitem.FParentListId = item.FParentListId; newitem.children = selectchildren(item.FProductListID, _list); lists.Add(newitem); } } return lists; }
public void GetProductList() { List<PortalProductListTree> lists = new List<PortalProductListTree>(); List<PortalProductList> lists1 = new List<PortalProductList>(); PortalProductListBiz biz = new PortalProductListBiz(); lists1 = biz.Select(); PortalProductListTreeBiz treebiz = new PortalProductListTreeBiz(); lists = treebiz.select(lists1); PortalProductListTree newitem = new PortalProductListTree(); newitem.FParentListId = 0; newitem.FProductListName = "根目录"; newitem.FProductListOrder = 10; newitem.FParentListId = 0; newitem.children = lists; List<PortalProductListTree> newlists = new List<PortalProductListTree>(); newlists.Add(newitem); string datasource = treebiz.ConvertToJson(newlists); Response.Write(datasource); }