Skip to content

Instantly share code, notes, and snippets.

Created August 29, 2016 09:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/bfbb242302885d43fecce779260c3ea6 to your computer and use it in GitHub Desktop.
Save anonymous/bfbb242302885d43fecce779260c3ea6 to your computer and use it in GitHub Desktop.
TryCF Gist
<cfscript>
TestData = querynew("id,parentId,nodeText");
queryAddRow(TestData,{id:1,nodeText:"File" });
queryAddRow(TestData,{id:2,nodeText:"New",parentId:1});
queryAddRow(TestData,{id:3,nodeText:"File",parentId:2});
queryAddRow(TestData,{id:4,nodeText:"Folder",parentId:2});
queryAddRow(TestData,{id:5,nodeText:"Edit"});
queryAddRow(TestData,{id:6,nodeText:"Copy",parentId:5});
queryAddRow(TestData,{id:7,nodeText:"Cut",parentId:5});
queryAddRow(TestData,{id:8,nodeText:"Paste",parentId:5});
queryAddRow(TestData,{id:9,nodeText:"Help"});
queryAddRow(TestData,{id:10,nodeText:"About",parentId:9});
result = [];
memory = {};
for( child in TestData ){
memory[ child.id ] = { 'nodeText' : child.nodeText };
if( len( child.parentID )){
if( not structKeyExists( memory[ child.parentID ] , 'children' )){
memory[ child.parentID ]['children'] = [];
}
memory[ child.parentID ]['children'].append( memory[ child.id ] );
}else{
result.append( memory[ child.id ] );
}
}
writeDump( result );
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment