description author sellardoor
 *  date param { String } variable export function getQueryVariable ( variable ) { var query = window . location . search . substring ( 1 ) ; var vars = query . split ( '&' ) ; for ( var i = 0 ; i < vars . length ; i ++ ) { var pair = vars [ i ] . split ( '=' ) ; if ( pair [ 0 ] == variable ) { return pair [ 1 ] ; } } return '' ; } param { Array } data interface arrayToTreeType { author : string ; avatar : string ; content : string ; pid : string ; type : string ; _id : string ; date : number ; [ propsName ] : any ; } export function arrayToTree ( data ) { let result = [ ] ; let map = { } ; data . forEach ( item => { map [ item . _id ] = item ; } ) ; data . forEach ( item => { let parent = map [ item . pid ] ; if ( parent ) { ( parent . children || ( parent . children = [ ] ) ) . push ( item ) ; } else { result . push ( item ) ; } } ) ; return result ; }