zoukankan      html  css  js  c++  java
  • 递归 无穷找子类的递归

    ///id要找的父类的id
    ///把找到的子类的id存放到idList中 
    private void GetAllSonPlateId(Guid id, ref List<Guid> idList)
            {
                try
                {
                    List<Guid> gets = _videoR.GetSonId(id);
                    if (gets.Count > 0)
                    {
                        foreach (Guid item in gets)
                        {
                            idList.Add(id);
                            GetAllSonPlateId(item, ref idList);
                        }
                    }
                    else
                    {
                        idList.Add(id);
                    }
                }
                catch (Exception)
                {
                }
            }
    
     /// <summary>
            /// 获得一个栏目的子栏目的idList
            /// </summary>
            /// <returns></returns>
            public List<Guid> GetSonId(Guid id)
            {
                List<Guid> idList = new List<Guid>();
                
                try
                {
                    var list = from plate in _db.Plate
                               where plate.ParentID == id
                               select plate.ID;
                    idList.AddRange(list.ToList<Guid>());
                    return idList;
                }
                catch (Exception)
                {
                    return idList;
                }
            }
    

    第二个代码

      /// <summary>
        /// 词条的列表  有百科类型
        /// </summary>
        public class WordList
        {
            public string BaikeType { get; set; }
            public Guid BaikeTypeID { get; set; }
            public List<Word> List { get; set; }
        } 
    
    
    /// <summary>
            /// 词条列表
            /// </summary>
            /// <returns></returns>
            [HttpPost]
            public ActionResult citiaolist(Guid? id)
            {
                if (id.HasValue)
                {
                    List<BaiKeType> baikelist = new List<BaiKeType>();
                    List<WordList> list = new List<WordList>();
                    List<WordList> self = _baikeR.GetOneCitiaoList(id.Value);
                    if (self != null)
                    {
                        list = list.Concat(self).ToList();
                    }
                    GetBaikeTypeSon(id.Value, ref baikelist);
                    foreach (BaiKeType item in baikelist)
                    {
                        List<WordList> temp = _baikeR.GetOneCitiaoList(item.ID);
                        if (temp != null)
                        {
                            list = list.Concat(temp).ToList();
                        }
                    }
                    ViewData["list"] = list;
                }
                else
                {
                    ViewData["list"] = _baikeR.GetCitiaoList();
                }
                return View();
            }
    //找到这个类别的所有子类别,返回到list中
            private void GetBaikeTypeSon(Guid id, ref List<BaiKeType> list)
            {
                try
                {
                    List<BaiKeType> baikelist = _baikeR.GetBaikeTypeListByParentID(id);
                    if (baikelist != null && baikelist.Count > 0)
                    {
                        list = list.Concat(baikelist).ToList();
                        foreach (BaiKeType item in baikelist)
                        {
                            GetBaikeTypeSon(item.ID, ref list);
                        }
                    }
                }
                catch { }
            }
    
  • 相关阅读:
    Mac保留Python2安装Python3(Anaconda3)
    Mybatis Plugin 以及Druid Filer 改写SQL
    Jackson替换fastjson
    Java单元测试 Http Server Mock框架选型
    应用中有多个Spring Property PlaceHolder导致@Value只能获取到默认值
    RabbitMQ Policy的使用
    Collectors.toMap不允许Null Value导致NPE
    php 删除标签
    php 替换标签
    jquery拼接html
  • 原文地址:https://www.cnblogs.com/nanxiaoxiang/p/2723982.html
Copyright © 2011-2022 走看看