Hi guys I''m working on a tree-view control to use in a project. The plan is to support: lazy loading of nodes click-to-edit-label drag and drop nodes creation of nodes deletion of nodes limiting nodes from changing levels adding new nodes standard expand/collapse dropping nodes on closed folders automatic opening of closed folders The plan is to release the tree to the community eventually, but it''s browser specific at the moment so that will be a while off. I looked at the extjs tree, and have decided not to use it because it only seems to work with prototype 1.5, same with taffeltree and my project uses 1.6 extensively. I''m trying to keep it simple, only 220 lines so far and not much refactoring for code size. Anyway, if I have a dom object, which is a folder, I need to know how deep in the tree it is. I don''t really want to store this on the dom element itself as it introduces issues with keeping it up to date when nodes are moved, so i''m thinking about how to get it''s level. I was thinking that var depth = this.ancestors().inject(0,function(depth,parent){ if ( parent.hasClassName(''folder'')) depth++; return depth; }); if(this.up().hasClassName(''folder'')) depth--; Would give me the number of folders deep for the current ''folder''. (the -- is because if ''this'' is a folder, it actually belongs to the level above, even though it''s in the same dom level as the items for that folder. Is there a better way of writing this? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Why not have a simple node class that keeps track of its own depth and indexes all the descendants? here is a quick idea: http://pastie.caboo.se/130989 - Ken Snyder Gareth Evans wrote:> Hi guys > > I''m working on a tree-view control to use in a project. > The plan is to support: > > lazy loading of nodes > click-to-edit-label > drag and drop nodes > creation of nodes > deletion of nodes > limiting nodes from changing levels > adding new nodes > standard expand/collapse > dropping nodes on closed folders > automatic opening of closed folders > > The plan is to release the tree to the community eventually, but it''s > browser specific at the moment so that will be a while off. > > I looked at the extjs tree, and have decided not to use it because it > only seems to work with prototype 1.5, same with taffeltree and my > project uses 1.6 extensively. > I''m trying to keep it simple, only 220 lines so far and not much > refactoring for code size. > > Anyway, if I have a dom object, which is a folder, I need to know how > deep in the tree it is. I don''t really want to store this on the dom > element itself as it introduces issues with keeping it up to date when > nodes are moved, so i''m thinking about how to get it''s level. > I was thinking that > > var depth = this.ancestors().inject(0,function(depth,parent){ > if (parent.hasClassName(''folder'')) depth++; return depth; }); > if(this.up().hasClassName(''folder'')) depth--; > > Would give me the number of folders deep for the current ''folder''. > (the -- is because if ''this'' is a folder, it actually belongs to the > level above, even though it''s in the same dom level as the items for > that folder. > > Is there a better way of writing this? > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---