>> I have been writing CF code since 3.x and have NEVER used
>> CFScript. I have never actually found a need.
> <cfscript> does have some speed benefits when it comes to
> recursively calling something, such as building a tree. You
> can do the same with a custom tag, but it's slower. Although,
> that benefit isn't always very useful because you can't pull
> from the database within <cfscript> in CF 5.0.
Recursive UDF's are great ... As you mentioned, it can make building a
tree'd display much easier, as I've done several times... and haven't had
problems in CF 5 due to not being able to embed a query in the UDF... I
actually didn't want the query there, I wanted the query further up, that
way, I could easily draw a single query with all of the data to be
displayed, defined the function which would call itself and either use the
query directly from the variables scope or pass the query as an argument to
the UDF. Then I could output the entire tree with something like ...
<cfquery name="rstree" datasource="...">
SELECT itemid, parentid, itemname
FROM mytable
ORDER BY parentid, itemname
</cfquery>
<cfoutput>#ShowChildrenOf(rstree,0)#</cfoutput>
The function definition looks something like
function ShowChildrenOf(rsTree,parent) {
var x = ListFind(ValueLIst(rsTree.parentid),parent);
if (x) {
while ( x lte rstree.recordcount
AND rstree.parentid[x] is parent ) {
writeOutput("<div
style=""margin-left:10px;"">#rstree.itemname[x]#");
ShowChildrenOf(rstree.itemid[x]); writeOutput("</div>");
}
}
return "";
}
If the tree is particularly large, this has the potential to save a _lot_ of
processing time...
Isaac
www.turnkey.to
954-776-0046
______________________________________________________________________
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists