skyline 递归查找信息树中全部节点

2021年09月15日 阅读数:1
这篇文章主要向大家介绍skyline 递归查找信息树中全部节点,主要内容包括基础应用、实用技巧、原理机制等方面,希望对大家有所帮助。
  int root = sgworld.ProjectTree.GetNextItem(0, ItemCode.ROOT);
            string tree = BuildTreeRecursive(root, 1);
private string BuildTreeRecursive( int current, int indent) //递归函数,模糊查找
                {
                         string padding = "";
                         for ( int i = 0; i < indent * 3; i++)
                                padding += "-";    
                         string result = "";
                         // iterate over all siblings of current node
                         while (current > 0)
                        {
                             // append node name to the tree string
                                 string currentName = sgworld.ProjectTree.GetItemName(current);
                                result += padding + currentName + "\r\n";
                                 // if current node is group, recursively build tree from its first child;
                                 if (sgworld.ProjectTree.IsGroup(current))
                                {
                                         int child = sgworld.ProjectTree.GetNextItem(current, ItemCode.CHILD);
                                        result += BuildTreeRecursive(child, indent + 1);
                                }
                                current = sgworld.ProjectTree.GetNextItem(current,ItemCode.NEXT);
                                 // move to next sibling                                
                        }
                         return result;
                }