
728
DEVELOPING
COLDFUSION 9 APPLICATIONS
Requesting and Presenting Information
Las
t
upda
te
d 8/5/2010
Structuring tree controls
Tree controls built with the
cftree
tag can be complex. Knowing how to specify the relationship between multiple
cftreeitem
entries helps you handle the most complex
cftree
constructs.
Creating a one-level tree control
The following example consists of a single root and some individual items:
<cfquery name="deptquery" datasource="cfdocexamples">
SELECT Dept_ID, FirstName || ' ' || LastName
AS FullName
FROM Employee
ORDER BY Dept_ID
</cfquery>
<cfform name="form1" action="submit.cfm">
<cftree name="tree1">
<cftreeitem value="FullName"
query="deptquery"
queryasroot="Department">
img="folder,document">
</cftree>
<br>
<cfinput type="submit" value="Submit">
</cfform>
Creating a multilevel tree control
When populating a
cftree
control, you create the multilevel structure of the tree by specifying a parent for each item
in the tree. The
parent
attribute of the
cftreeitem
tag allows your
cftree
tag to show relationships between
elements in the tree.
In this example, every
cftreeitem
tag, except the top level Divisions, specifies a parent. For example, the
cftreeitem
tag specifies Divisions as its parent.
The following code populates the tree directly, not from a query: