parent
37b6c90dca
commit
5fc14c682d
3 changed files with 29 additions and 1 deletions
@ -0,0 +1,16 @@ |
|||||||
|
export const connectToParent = (list) => { |
||||||
|
let comments = [] |
||||||
|
for(let item of list){ |
||||||
|
comments.push({...item, child : []}); |
||||||
|
} |
||||||
|
|
||||||
|
for(let comment1 of comments){ |
||||||
|
if(comment1.pid !== null){ |
||||||
|
const index = comments.indexOf(comments.filter((comment2) => comment2.id === comment1.pid)[0]); |
||||||
|
comments[index] = {...comments[index], child : [comment1]}; |
||||||
|
}else{ |
||||||
|
console.log('nist :(') |
||||||
|
} |
||||||
|
} |
||||||
|
console.log(comments); |
||||||
|
} |
Loading…
Reference in new issue