示例#1
0
        public static List <znode> ToJson(IEnumerable <ZTree> datasource, string urlPrefix, string checkedId)
        {
            var znodes = new List <znode>();

            if (datasource == null)
            {
                return(znodes);
            }
            foreach (var f in datasource.Where(x => string.IsNullOrEmpty(x.ParentID)))
            {
                var father = new znode
                {
                    id         = f.Id,
                    isParent   = true,
                    name       = f.Name,
                    isSelected = checkedId == f.Id,
                    open       = true,
                    target     = "_self",
                    url        = urlPrefix + (urlPrefix.IndexOf("?") >= 0 ? "&fid=" + f.Id : "?fid=" + f.Id),
                };
                recursive(datasource, father, urlPrefix, checkedId);
                znodes.Add(father);
            }
            return(znodes);
        }
示例#2
0
        public static void recursive(IEnumerable <ZTree> datasource, znode father, string urlPrefix, string checkedId)
        {
            var children = datasource.Where(x => x.ParentID == father.id);

            foreach (var child in children)
            {
                var ch = new znode
                {
                    id         = child.Id,
                    isParent   = false,
                    name       = child.Name,
                    isSelected = checkedId == child.Id,
                    open       = true,
                    target     = "_self",
                    url        = urlPrefix + (urlPrefix.IndexOf("?") >= 0 ? "&fid=" + child.Id : "?fid=" + child.Id),
                };
                father.children.Add(ch);
                recursive(datasource, ch, urlPrefix, checkedId);
            }
        }