zoukankan      html  css  js  c++  java
  • 递归树

            /// <summary>
            /// 递归获取树
            /// </summary>
            /// <param name="parentId">父节点ID</param>
            /// <param name="originList">原始数据</param>
            /// <returns></returns>
            public List<Bd_ProductCategory_Tree_ViewModel> GetBdProductCategoryTreeViewList(int parentId, List<Bd_ProductCategory_ViewModel> originList)
            {
                List<Bd_ProductCategory_Tree_ViewModel> treeList = new List<Bd_ProductCategory_Tree_ViewModel>();
                List<Bd_ProductCategory_ViewModel> list = originList.Where(s => s.ParentId == parentId).ToList();
                foreach (var item in list)
                {
                    Bd_ProductCategory_Tree_ViewModel bdProductCategoryTreeViewModel = new Bd_ProductCategory_Tree_ViewModel();
                    if (!string.IsNullOrEmpty(item.ProductCategoryName))
                    {
                        bdProductCategoryTreeViewModel.Key = item.ProductCategoryName;
                        bdProductCategoryTreeViewModel.Title = item.ProductCategoryName;
                    }
    
                    List<Bd_ProductCategory_Tree_ViewModel> childList = GetBdProductCategoryTreeViewList(item.Id, originList);
                    if (childList != null && childList.Count > 0)
                    {
                        bdProductCategoryTreeViewModel.Children = childList;
                    }
                    treeList.Add(bdProductCategoryTreeViewModel);
    
                }
                return treeList;
            }
    public class Bd_ProductCategory_Tree_ViewModel
        {
            /// <summary>
            /// 标题
            /// </summary>
            [JsonProperty("Title")]
            public string Title { get; set; }
            /// <summary>
            /// 关键词
            /// </summary>
            [JsonProperty("Key")]
            public string Key { get; set; }
            /// <summary>
            /// 子品类
            /// </summary>
            [JsonProperty("Children")]
            public List<Bd_ProductCategory_Tree_ViewModel> Children { get; set; }
        }
    将来的你,一定会感谢现在努力的自己!
  • 相关阅读:
    线上答题竞赛小程序
    成语答题小程序源码
    lua --- 局部变量
    lua --- 逻辑运算符小结
    Lua --- 输入一个数字,输出阶乘
    lua闭包实现迭代器遍历数组
    lua中的闭包概念的学习笔记
    Unity --- 纹理为什么要设置为2的N次方
    Unity --- 如何降低UI的填充率
    RPG游戏中如何判断敌人是否在玩家的攻击范围之内
  • 原文地址:https://www.cnblogs.com/GreatPerson/p/8418466.html
Copyright © 2011-2022 走看看