Skip to content Skip to sidebar Skip to footer

How To Create Nested Group Of Properties

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}, {nam

Solution 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;
}

Post a Comment for "How To Create Nested Group Of Properties"