• 递归 无穷找子类的递归


    ///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 { }
            }
    
  • 相关阅读:
    MATLAB远程桌面打开失败解决办法
    Windows 10 激活步骤
    Windows 10 重装技巧
    Office2019部署代码
    vi命令行命令的积累
    github项目cim(命令行即时通讯), HashedWheelTimer学习笔记
    java读取资源文件/打jar包后读取资源文件的区别
    vmware虚拟机网络配置(物理机能用ssh连接虚拟机, 虚拟机能共享物理机网卡上外网)仅主机模式,nat模式应该也可以
    spring cloud 组件学习 hystrix学习
    netty优化学习积累+++++++
  • 原文地址:https://www.cnblogs.com/nanxiaoxiang/p/2723982.html
Copyright © 2020-2023  润新知