// // var data = [ // // {id: 1, address: "安徽", parent_id: 0}, // // {id: 2, address: "江苏", parent_id: 0}, // // {id: 3, address: "合肥", parent_id: 1}, // // {id: 4, address: "庐阳区", parent_id: 3}, // // {id: 5, address: "大杨镇", parent_id: 4}, // // {id: 6, address: "南京", parent_id: 2}, // // {id: 7, address: "玄武区", parent_id: 6}, // // {id: 8, address: "梅园新村街道", parent_id: 7}, // // {id: 9, address: "上海", parent_id: 0}, // // {id: 10, address: "黄浦区", parent_id: 9}, // // {id: 11, address: "外滩", parent_id: 10}, // // {id: 12, address: "安庆", parent_id: 1} // // ]; // var data = [ { id: 1, name: 'html', belongto: 0, about: '22' }, // { id: 2, name: 'css', belongto: 0, about: '2256' }, // { id: 3, name: 'js', belongto: 1, about: '5422' }, // { id: 4, name: 'js', belongto: 2, about: '5422' }, // { id: 5, name: 'js', belongto: 3, about: '5422' }, // { id: 6, name: 'js', belongto: 1, about: '5422' }, // { id: 7, name: 'js', belongto: 1, about: '5422' }, // { id: 8, name: 'js', belongto: 5, about: '5422' }, // { id: 9, name: 'js', belongto: 8, about: '5422' }, // { id: 10, name: 'js', belongto: 8, about: '5422' }, // { id: 11, name: 'js', belongto: 10, about: '5422' }, // { id: 12, name: 'js', belongto: 11, about: '5422' } ] // // function findeBelong(data, index) { // let array = []; // for (let i = data.length-1; i >= 0 ; i--) { // if(data[i].belongto == index){ // const obj = { // id: data[i].id, // name: data[i].name, // desc: data[i].about, // children: [] // } // array.push(obj); // data.splice(i,1); // } // } // return array; // } // // function sortTree(arr,all){ // let tree = (arr,all)=>{ // for (let i = 0; i < arr.length; i++) { // let item = findeBelong(all,arr[i].id); // for (let j = 0; j < item.length; j++) { // const obj = { // id: item[j].id, // name: item[j].name, // desc: item[j].desc, // children: [] // } // arr[i].children.push(obj); // } // tree(arr[i].children,all) // } // } // tree(arr,all) // } // let fa = findeBelong(data,0); // sortTree(fa,data); // console.log(fa); // console.log(data); // /* // * 1. 先找出ID==0的菜单 // * 2. 选中第一个ID的菜单,去菜单表中寻找是否有其子菜单,找到之后构建插入然后删除这个,然后递归查这一个的子菜单 // * // * */