/// <summary> /// 将父子级数据结构转换为普通list /// </summary> /// <param name="list"></param> /// <returns></returns> public static List<UniWater_MenuInfo> GetMenuInfoList(List<UniWater_MenuInfo> list) { List<UniWater_MenuInfo> Resultlist = new List<UniWater_MenuInfo>(); foreach (var item in list) { OperationChildData(Resultlist, item); Resultlist.Add(item); } return Resultlist; } /// <summary> /// 递归子级数据 /// </summary> /// <param name="treeDataList">树形列表数据</param> /// <param name="parentItem">父级model</param> public static void OperationChildData(List<UniWater_MenuInfo> AllList, UniWater_MenuInfo item) { if (item.children != null) { if (item.children.Count > 0) { AllList.AddRange(item.children); foreach (var subItem in item.children) { OperationChildData(AllList, subItem); } } } }
转自:http://www.manongjc.com/detail/17-cwfkfdaeqrbjqyr.html