Created
August 29, 2016 17:24
-
-
Save anonymous/521ce8e41fdff8d4058b0798c32af931 to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
function makeATree( testData ) { | |
var parents = { "" = {} }; | |
for ( var row in testData ) { | |
parents[ row.id ] = { "nodeText" = row.nodeText }; | |
var parent = parents[ row.parentId ]; | |
param parent.children=[ ]; | |
parent.children.append( parents[ row.id ] ); | |
} | |
return parents[ "" ].children; | |
} | |
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}); | |
writeDump( makeATree( testData ) ); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment