The child nodes of the tree structure to match the path

1  / * recursive matching menu path * / 
2          recursionMenu: function (recursionField = '', MENU = []) {
 . 3              the let menuTree = {
 . 4                  title: 'Home' ,
 . 5                  URL: '/ Pages / index' ,
 . 6                  Children: MENU
 . 7              };
 . 8              the let _menu = []; // array of paths 
. 9              the let = FindIT to false ; // matches to 
10              the let getPath = function (Tree) {
 . 11                 _menu.push({
12                     title: tree.title,
13                     path: tree.url
14                 });
15                 if (tree.title === recursionField) {
16                     findIt = true;
17                     return;
18                 }
19                 if (tree.children && tree.children.length > 0) {
20                     for (let i = 0; i < tree.children.length; i++) {
21                         getPath(tree.children[i]);
22                         if (findIt) return;
23                     }
24                     _menu.pop();
25                 } else if (!tree.children || tree.children.length === 0) {
26                     _menu.pop();
27                 }
28             };
29             getPath(menuTree);
30             return _menu;
31         }

 

Guess you like

Origin www.cnblogs.com/chenzeyongjsj/p/11888321.html
Recommended