zoukankan      html  css  js  c++  java
  • 无限层级数

    public class ResList
        {
            public int ID { get; set; }
            public List<ResList> Child { get; set; } = null;
            public int Parent { get; set; }
            public int Rank { get; set; }
        }

      数据就是那种有父级ID的那种

    List<ResList> reslist = new List<ResList>();//新的数据
                List<ResList> alllist = new List<ResList>();//原始数据
                //加载原始数据
                for (int i = 1; i < 10000; i++)
                {
                    int j = 0;
                    while (Math.Pow(10, j) <= i)
                    {
                        j++;
                    }
    
                    alllist.Add(new ResList() { ID = i, Parent = i / 10, Rank = j });
                }
                //加载原始数据完成
    
    
                //下面是处理方法
                Dictionary<int, ResList> dic = new Dictionary<int, ResList>();
    
                foreach (ResList res in alllist)
                {
                    dic.Add(res.ID, res);
    
                }
                foreach (ResList res in dic.Values)
                {
                    if (dic.ContainsKey(res.Parent))
                    {
                        if (dic[res.Parent].Child == null)
                        {
                            dic[res.Parent].Child = new List<ResList>();
                        }
                        dic[res.Parent].Child.Add(res);
                    }
                }
                //得到最终的数据List
                reslist = dic.Values.Where(t => t.Parent == 1).ToList();
  • 相关阅读:
    flexible
    arcgis
    vue 语法糖
    sass 的安装 编译 使用
    nodeJs
    微信小程序
    linux cgroups 简介
    git命令
    sublime笔记
    工程优化学习(进退法、黄金分割法、二次插值法、三次插值法、最速下降法)
  • 原文地址:https://www.cnblogs.com/Kendy/p/14930946.html
Copyright © 2011-2022 走看看