parseTree

134 阅读1分钟
export const parseTree = (all) => {  var MENU_DATA = []  all.forEach(function(it) {    if (!MENU_DATA.find(function(ele) {      return ele.id == it.id    })) {      MENU_DATA.push(it)    }  })  MENU_DATA.forEach(function(it) {    MENU_DATA.forEach(function(ele) {      if (it.id == ele.parentId) {        if (it.children) {          it.children.push(ele)        } else {          it.children = new Array()          it.children.push(ele)        }      }    })  })  var resourceTree = MENU_DATA.filter(function(it) {    return it.parentId == "" || it.parentId == 0;  })  return resourceTree}