示例#1
0
 public static List<PositionNodeVm> List(List<PositionNode> pnl)
 {
     var vml = new List<PositionNodeVm>();
     for (int i = 0; i < pnl.Count; i++)
     {
         var pnv = new PositionNodeVm(pnl[i]);
         if (i == pnl.Count - 1)
         {
             // *note*, state is lazy-populated property
             pnv.state += " jstree-last"; // this only works for first tier of lazy-loaded subnodes.
         }
         vml.Add(pnv);
     }
     return vml;
 }
示例#2
0
        public static List<PositionNodeVm> VmTreesFromList(List<PositionNode> l)
        {
            var tl = new List<PositionNodeVm>(); // holds tree-sorted list of root nodes
            var nt = new List<PositionNodeVm>(); // nesting tracker

            var root = new PositionNodeVm(l[0]);
            tl.Add(root); // first element is always root
            nt.Add(root);
            int rootlevel = l[0].depth;
            int level = rootlevel;

            for (int i = 1; i < l.Count; i++)
            {
                var n = new PositionNodeVm(l[i]);
                var depth = n._model.depth;
                if (depth > level)
                {
                    if (nt.Count >= depth - rootlevel + 1)
                    {
                        nt[depth - rootlevel] = n;
                    }
                    else
                    {
                        nt.Add(n);
                    }
                    nt[level - rootlevel].children.Add(nt[depth - rootlevel]);
                }
                else if (depth <= level && depth > rootlevel)
                {
                    nt[depth - rootlevel] = n;
                    nt[depth - rootlevel - 1].children.Add(n);
                }
                else if (depth == rootlevel)
                {
                    // this should only happen if multiple roots are allowed.
                    tl.Add(n);
                    nt[0] = n;
                }

                // outdenting...set preceding node last-sibling states if applicable:
                if (depth < level) {
                    for (int d = depth; d < level; d++)
                    {
                        nt[d].state += " jstree-last";
                    }
                }
                if (i == l.Count - 1) // final record; set this and any ancestors to last:
                {
                    n.state += " jstree-last";
                    for (int j = rootlevel; j < depth; j++)
                    {
                        nt[j].state += " jstree-last";
                    }
                }

                level = depth;
            }
            return tl;
        }