Example #1
0
        /// <summary>
        /// 递归组装tree对象
        /// </summary>
        /// <param name="thisValue"></param>
        /// <returns></returns>
        public static List <LayuiTreeModel> ToLayuiTree(this List <LayuiTreeModel> thisValue)
        {
            if (thisValue == null)
            {
                return(thisValue);
            }
            List <LayuiTreeModel> reval = new List <LayuiTreeModel>();
            var firsts = thisValue.Where(it => it.level == 0).ToList();

            foreach (var item in firsts)
            {
                var newItem = new LayuiTreeModel();
                ToLayuiTree_Part(item, newItem, thisValue);
                reval.Add(newItem);
            }
            return(reval);
        }
Example #2
0
        private static void ToLayuiTree_Part(LayuiTreeModel oldItem, LayuiTreeModel newItem, List <LayuiTreeModel> allTypeList)
        {
            newItem.id     = oldItem.id;
            newItem.name   = oldItem.name;
            newItem.spread = oldItem.spread == null?true: oldItem.spread;
            newItem.alias  = oldItem.alias;
            newItem.level  = oldItem.level;
            var childs = allTypeList.Where(it => it.parentId.TryToInt() == newItem.id.TryToInt()).ToList();
            var isAny  = childs.IsValuable();

            if (isAny)
            {
                newItem.children = new List <LayuiTreeModel>();
                foreach (var child in childs)
                {
                    LayuiTreeModel childNewItem = new LayuiTreeModel();
                    ToLayuiTree_Part(child, childNewItem, allTypeList);
                    newItem.children.Add(childNewItem);
                }
            }
        }