0

I am Trying to create nested group of my javascript raw object.

item=[ {name:'Root1',id:1,parentId:null}, {name:'Root2',id:2,parentId:null}, {name:'Root3',id:4,parentId:null}, {name:'Root1.1',id:4,parentId:1}, {name:'Root1.1.1',id:5,parentId:4}, {name:'Root4',id:6,parentId:null} ]; 

this is my raw data,

I want this data in format some like bellow

var modified= [ { title:Root1, id:1, chields: { title:'Root 1.1', id:4, clields: { title:'Root 1.1.1', id:5, chield: { title:'New', id:null } } } } ]; 
1
  • Have you tried searching? I'm sure I have answered and seen good answer on SO Commented Nov 6, 2017 at 5:29

1 Answer 1

1

I got My Solution here

 var children = _.filter( array, function(child){ return child.parentid == parent.id; }); if( !_.isEmpty( children ) ){ if( parent.id == 0 ){ tree = children; }else{ parent['children'] = children } _.each( children, function( child ){ unflatten( array, child ) } ); } return tree; } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.