You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm missing a functionality for only selecting the outer leaf nodes of the tree without selecting nodes that act as a parent. The following method will fetch the outer leafs that are not a parent.
defall_leafsall=[]self.children.eachdo |category|
all << categoryifcategory.children.empty?root_children=category.all_leafs.flattenall << root_childrenunlessroot_children.empty?end# if there are no leafs then include itselfall << selfifself.children.empty?returnall.flattenend
I use it in combination with
(some tree model).map { |period| period.all_leafs.map(&:id).uniq }.flatten
Maybe this could be added (the concept) in a better way then recursively looping through the tree. Or is there a method that already returns the outer leaf nodes?
The text was updated successfully, but these errors were encountered:
Hello,
I'm missing a functionality for only selecting the outer leaf nodes of the tree without selecting nodes that act as a parent. The following method will fetch the outer leafs that are not a parent.
I use it in combination with
(some tree model).map { |period| period.all_leafs.map(&:id).uniq }.flatten
Maybe this could be added (the concept) in a better way then recursively looping through the tree. Or is there a method that already returns the outer leaf nodes?
The text was updated successfully, but these errors were encountered: