Ejemplo n.º 1
0
        /// <summary>
        /// 获取TreeSelect节点下所有子节点
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="self"></param>
        /// <param name="order"></param>
        /// <returns></returns>
        public static List <TreeSelectListItem> GetTreeSelectChildren(this TreeSelectListItem self, Func <TreeSelectListItem, object> order = null)
        {
            List <TreeSelectListItem> rv = new List <TreeSelectListItem>();
            var children = self.Children;

            if (order != null && children != null)
            {
                children = children.OrderBy(order).ToList();
            }
            if (children != null && children.Count() > 0)
            {
                var dictinct = children.Where(x => x.Id != self.Id).ToList();
                foreach (var item in dictinct)
                {
                    rv.Add(item);
                    //递归添加子节点的子节点
                    rv.AddRange(item.GetTreeSelectChildren(order));
                }
            }
            return(rv);
        }
        public List <TreeSelectListItem> GenerateChildTreeSelectItems(string parentElementId)
        {
            var childTreeSelectList = new List <TreeSelectListItem>();
            var childElementList    = DC.Set <EnterpriseReviewElement>().Where(e => e.ParentElementId == parentElementId && e.IsValid.Equals(true)).OrderBy(x => x.Order).ToList();

            if (childElementList.Count() > 0)
            {
                childElementList.ForEach(x =>
                {
                    var treeSelectListItem = new TreeSelectListItem()
                    {
                        Id   = x.ID.ToString(),
                        Text = $"{x.Order}.{x.ElementName}"
                    };
                    if ((int)x.Level < 4)
                    {
                        treeSelectListItem.Children = GenerateChildTreeSelectItems(x.ID.ToString());
                    }
                    childTreeSelectList.Add(treeSelectListItem);
                });
            }
            return(childTreeSelectList);
        }