遍历目录树

  1. function getTree(ary) {
  2. return ary.map(v => {
  3. const item = {
  4. title: v.title, //这是创建的新对象 根据需要的键随意更改
  5. };
  6. if (v.children) item.children = getTree(v.children);
  7. return item;
  8. });
  9. }