从 extendscript 中的路径递归填充树视图

Recursively populate treeview from paths in extendscript

我正在为 Adob​​e After Effects 开发一个扩展脚本函数,它需要能够将如下所示的文件路径列表转换为树视图。到目前为止,这是我的代码,它顺利地完成了第一个 "level",但我在递归方面遇到了问题。非常感谢您的帮助,我正在为这个问题苦苦挣扎,但似乎还无法让它发挥作用!

{
    //----| Build UI
    var stImporterWin = new Window("palette", "ST Import Panel", undefined, {resizeable:true});
        stImporterWin.orientation = "column";

    var imageSequenceGroup = stImporterWin.add("group");
            imageSequenceGroup.alignment = ["fill", "fill"];
            imageSequenceGroup.orientation = "column";
            var imageSequenceTree = imageSequenceGroup.add("treeview");
                imageSequenceTree.preferredSize = [600,650];
                imageSequenceTree.alignment = ["fill", "fill"];


    stImporterWin.onResize = function () {
        this.layout.resize();
    }

    stImporterWin.show();

    filesArray = ["//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image2_0001.txt",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image3.0001.txt",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image_001.txt",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/0040-Major Trans M13_Logo_v02.xml",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.AO.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.MultiMatteElement.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.RGB_color.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySelfIllumination.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySpecular.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRayZDepth.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.origRGB.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/Thumbs.db",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/0040-Major Trans M13_logo_02.0080.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/Thumbs.db",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/AO/0040-Major Trans M13_logo_02._AO0080.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRaySelfIllumination/0040-Major Trans M13_logo_02._VRaySelfIllumination0080.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRaySpecular/0040-Major Trans M13_logo_02._VRaySpecular0080.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRayZDepth/0040-Major Trans M13_logo_02._VRayZDepth0080.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/T1/Thumbs.db",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.AO.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.MultiMatteElement.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.RGB_color.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySelfIllumination.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySpecular.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRayZDepth.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.origRGB.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/Thumbs.db",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..AO.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..MatteText.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..RGB_color.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySelfIllumination.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySpecular.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRayZDepth.0000.png",
    "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..origRGB.0000.png"];

    rootFolder = File("//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders");

    var node0 = imageSequenceTree.add("node", rootFolder.fsName.replace(/\/g, "/"));
    node0.expanded = true;

    //build out arrays from the files
    for (var i = 0; i < filesArray.length; i++) {
        filesArray[i] = filesArray[i].split("/");
    }

    //recursive tree building
    var rootAsArray = rootFolder.fsName.replace(/\/g, "/").split("/");
    BuildChildNodes(rootAsArray, filesArray, node0, 0);


    // for debug purposes I added "killme" so that we only recurse once for now
    function BuildChildNodes (root, files, parentNode, killme) {
        alert("Root: " + root.join("/"));
        previousDirName = "";

        for (var i = 0; i < files.length; i++) {
            var currentPath = files[i];

            if (currentPath.length > root.length+1) {
                // we got a sub-folder so add it to the tree if unique and recurse
                var dirName = currentPath[root.length];
                if (dirName != previousDirName) {
                    var newNode = parentNode.add("node", dirName);
                    newNode.expanded = true;
                    previousDirName = dirName;

                    // recurse
                    var newRoot = currentPath.slice(0, root.length+1);
                    var newFilesList = files.slice(i);
                    //make sure we only get this dir
                    for (var j = 0; j < newFilesList.length; j++) {
                        if (newFilesList[j].slice(0, root.length+1).join("/") != newRoot.join("/")) {
                            newFilesList = newFilesList.slice(0,j);
                            break;
                        }
                    };

                    if (killme == 0) {
                        alert("recursing " + newRoot.join("/"));
                        BuildChildNodes(newRoot, newFilesList, newNode, 1);
                    }

                }
            } else {
                // we got a file in this dir, add it to the tree
                var fileName = currentPath[root.length];
                var newNode = parentNode.add("item", fileName);
            }       
        }
    }
}

示例输入列表如下所示:

//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/test image2_0001.txt
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/test image3.0001.txt
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/test image_001.txt
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/0040-Major Trans M13_Logo_v02.xml
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.AO.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.MultiMatteElement.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.RGB_color.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySelfIllumination.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySpecular.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRayZDepth.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/0040-Major Trans M13_01_logo_.origRGB.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T1/Thumbs.db
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/0040-Major Trans M13_logo_02.0080.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/Thumbs.db
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/AO/0040-Major Trans M13_logo_02._AO0080.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/VRaySelfIllumination/0040-Major Trans M13_logo_02._VRaySelfIllumination0080.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/VRaySpecular/0040-Major Trans M13_logo_02._VRaySpecular0080.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Logo/T2/VRayZDepth/0040-Major Trans M13_logo_02._VRayZDepth0080.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/T1/Thumbs.db
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.AO.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.MultiMatteElement.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.RGB_color.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySelfIllumination.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySpecular.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.VRayZDepth.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/0040-Major Trans M13_01_text_.origRGB.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T1/Thumbs.db
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..AO.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..MatteText.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..RGB_color.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySelfIllumination.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySpecular.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRayZDepth.0000.png
//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..origRGB.0000.png

最后上面的内容看起来像:

//NY-18/02_Sequences/IntroVideo/0040-Major/Renders/
    test image2_0001.txt
    test image3.0001.txt
    test image_001.txt
    Logo/
        0040-Major Trans M13_Logo_v02.xml
        T1/
            0040-Major Trans M13_01_logo_.AO.0000.png
            0040-Major Trans M13_01_logo_.MultiMatteElement.0000.png
            0040-Major Trans M13_01_logo_.RGB_color.0000.png
            0040-Major Trans M13_01_logo_.VRaySelfIllumination.0000.png
            0040-Major Trans M13_01_logo_.VRaySpecular.0000.png
            0040-Major Trans M13_01_logo_.VRayZDepth.0000.png
            0040-Major Trans M13_01_logo_.origRGB.0000.png
            Thumbs.db
        T2/
            0040-Major Trans M13_logo_02.0080.png
            Thumbs.db
            AO/
                0040-Major Trans M13_logo_02._AO0080.png
            VRaySelfIllumination/
                0040-Major Trans M13_logo_02._VRaySelfIllumination0080.png
            VRaySpecular/
                0040-Major Trans M13_logo_02._VRaySpecular0080.png
            VRayZDepth/
                0040-Major Trans M13_logo_02._VRayZDepth0080.png
    T1/
        Thumbs.db
    Text/
        T1/
            0040-Major Trans M13_01_text_.AO.0000.png
            0040-Major Trans M13_01_text_.MultiMatteElement.0000.png
            0040-Major Trans M13_01_text_.RGB_color.0000.png
            0040-Major Trans M13_01_text_.VRaySelfIllumination.0000.png
            0040-Major Trans M13_01_text_.VRaySpecular.0000.png
            0040-Major Trans M13_01_text_.VRayZDepth.0000.png
            0040-Major Trans M13_01_text_.origRGB.0000.png
            Thumbs.db
        T2 ext/
            NY18_MajorTrans Ext_01_M13_text..AO.0000.png
            NY18_MajorTrans Ext_01_M13_text..MatteText.0000.png
            NY18_MajorTrans Ext_01_M13_text..RGB_color.0000.png
            NY18_MajorTrans Ext_01_M13_text..VRaySelfIllumination.0000.png
            NY18_MajorTrans Ext_01_M13_text..VRaySpecular.0000.png
            NY18_MajorTrans Ext_01_M13_text..VRayZDepth.0000.png
            NY18_MajorTrans Ext_01_M13_text..origRGB.0000.png

我通过删除递归稍微简化了您的代码。不需要它,因为您没有走层次结构;每个路径都有层次结构。

结果如下:

{
   //----| Build UI
   var stImporterWin = new Window("palette", "ST Import Panel", undefined, {resizeable:true});
   stImporterWin.orientation = "column";

   var imageSequenceGroup = stImporterWin.add("group");
   imageSequenceGroup.alignment = ["fill", "fill"];
   imageSequenceGroup.orientation = "column";
   var imageSequenceTree = imageSequenceGroup.add("treeview");
   imageSequenceTree.preferredSize = [600,650];
   imageSequenceTree.alignment = ["fill", "fill"];


   stImporterWin.onResize = function () {
      this.layout.resize();
   }

   stImporterWin.show();

   filesArray = ["//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image2_0001.txt",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image3.0001.txt",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/test image_001.txt",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/0040-Major Trans M13_Logo_v02.xml",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.AO.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.MultiMatteElement.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.RGB_color.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySelfIllumination.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRaySpecular.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.VRayZDepth.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/0040-Major Trans M13_01_logo_.origRGB.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T1/Thumbs.db",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/0040-Major Trans M13_logo_02.0080.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/Thumbs.db",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/AO/0040-Major Trans M13_logo_02._AO0080.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRaySelfIllumination/0040-Major Trans M13_logo_02._VRaySelfIllumination0080.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRaySpecular/0040-Major Trans M13_logo_02._VRaySpecular0080.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Logo/T2/VRayZDepth/0040-Major Trans M13_logo_02._VRayZDepth0080.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/T1/Thumbs.db",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.AO.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.MultiMatteElement.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.RGB_color.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySelfIllumination.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRaySpecular.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.VRayZDepth.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/0040-Major Trans M13_01_text_.origRGB.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T1/Thumbs.db",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..AO.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..MatteText.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..RGB_color.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySelfIllumination.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRaySpecular.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..VRayZDepth.0000.png",
      "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders/Text/T2 ext/NY18_MajorTrans Ext_01_M13_text..origRGB.0000.png"];

   rootPath = "//VFXJobs/NY-18/02_Sequences/IntroVideo/0040-Major Trans M13/Renders";

   var node0 = imageSequenceTree.add("node", rootPath);
   node0.expanded = true;

   //recursive tree building
   var rootAsArray = rootPath.split("/");

   //build out arrays from the files
   var subFilesArray = [];
   for (var i = 0; i < filesArray.length; i++) {
      var split = filesArray[i].split("/");
      subFilesArray[i] = split.slice(rootAsArray.length, split.length);
   }

   BuildChildNodes(subFilesArray, node0);

   function BuildChildNodes(subPaths, rootNode) {
      for (var i=0; i<subPaths.length; i++) {
         var subPath = subPaths[i];
         var curr = rootNode;

         for (var j=0; j<subPath.length-1; j++) {
            var path = subPath[j];
            var node = getItem(curr, path);

            if (node) {
               curr = node;
            } else {
               curr = curr.add("node", path);
            }
         }

         curr.add("item", subPath[subPath.length-1]);
      }
   }

   function getItem(node, text) {
      for (var i=0; i<node.items.length; i++) {
         var item = node.items[i];
         if (item.text === text) {
            return item;
         }
      }
      return null;
   }
}