对于任何寻找答案的人,我从 Cody 的链接中获取了代码,并让它为我工作(因为它不能正常工作)。谢谢科迪和夏兰!这里是:
<cfquery name="get_folders" datasource="#application.dsn#">
select folder_id, parent_folder_id, folder_name
from folders
order by folder_name
</cfquery>
<!--- Read all roots (no parent ID) --->
<cfquery name="get_parent_folders" dbtype="query">
select folder_id, folder_name
from get_folders
where parent_folder_id is null
</cfquery>
<ul class="tree">
<cfloop query="get_parent_folders">
<cfset processTreeNode(folderId=get_parent_folders.folderId, folderName=get_parent_folders.folder_name) />
</cfloop>
</ul>
<cffunction name="processTreeNode" output="true">
<cfargument name="folderId" type="numeric" />
<cfargument name="folderName" type="string" />
<!--- Check for any nodes that have *this* node as a parent --->
<cfquery name="LOCAL.qFindChildren" dbtype="query">
select folder_id, folder_name
from get_folders
where parent_folder_id = <cfqueryparam value="#arguments.folderId#" cfsqltype="cf_sql_integer" />
</cfquery>
<li>#arguments.folderName#
<cfif LOCAL.qFindChildren.recordcount>
<!--- We have another list! --->
<ul>
<!--- We have children, so process these first --->
<cfloop query="LOCAL.qFindChildren">
<!--- Recursively call function --->
<cfset processTreeNode(folderId=LOCAL.qFindChildren.folder_id, folderName=LOCAL.qFindChildren.folder_name) />
</cfloop>
</ul>
</cfif>
</li>
</cffunction>