Link to home
Start Free TrialLog in
Avatar of faisalmohi
faisalmohi

asked on

cftree need sub menu

Dear Expert,

how to get sub menu under each node

<cfquery name="getCourses" datasource="tree">
SELECT main.id_name, sub.id, sub.description
FROM sub INNER JOIN main ON sub.parent_id = main.id;
</cfquery>

in mdb file in "sub" table i assing parent id of sub table's id so each node under i can get sub node , also i need another sub node under this subnote , i mean dynamic and unlimited




<cfform name="studentForm" format="flash" width="1000" height="1000">
    <cftree name="courseTree" width="985" height="950" font="Arabic Transparent" fontsize="12.5">
        <cftreeitem
            query="getCourses"
            value="id_name,id"
            display="id_name,description" queryasroot="NO" expand="no">
    </cftree>
</cfform>



cfdocexamples.mdb
untitled.JPG
Avatar of Brijesh Chauhan
Brijesh Chauhan
Flag of India image

Use the PARENT attribute

say you have a sub-tree under Divisions, so you would have

<cftreeitem value="Divisions">
<cftreeitem value="Development"  
        parent="Divisions" img="folder">

so the Development would be under Divisions, specify the parent in there...

here is an example

<cfform name="form2" action="cfform_submit.cfm" format="html"> 
<cftree name="tree1" hscroll="No" vscroll="No" 
    border="No"> 
    <cftreeitem value="Divisions"> 
    <cftreeitem value="Development"  
        parent="Divisions" img="folder"> 
    <cftreeitem value="Product One"  
        parent="Development" img="document"> 
    <cftreeitem value="Product Two"  
        parent="Development"> 
    <cftreeitem value="GUI"  
        parent="Product Two" img="document"> 
    <cftreeitem value="Kernel"  
        parent="Product Two" img="document"> 
    <cftreeitem value="Product Three"  
        parent="Development" img="document"> 
    <cftreeitem value="QA"  
        parent="Divisions" img="folder"> 
    <cftreeitem value="Product One" 
        parent="QA" img="document"> 
    <cftreeitem value="Product Two"  
        parent="QA" img="document"> 
    <cftreeitem value="Product Three" 
        parent="QA" img="document"> 
    <cftreeitem value="Support" 
        parent="Divisions" img="fixed"> 
    <cftreeitem value="Product Two" 
        parent="Support" img="document"> 
    <cftreeitem value="Sales" 
        parent="Divisions" img="computer"> 
    <cftreeitem value="Marketing" 
        parent="Divisions" img="remote"> 
    <cftreeitem value="Finance" 
        parent="Divisions" img="element"> 
</cftree> 
</cfform>

Open in new window

In loop, you would have 2 do 2 loops and 2 queries, the first one will get the , and the second one will get the sub-menu's

something like this


<cfquery name="getCourses" datasource="tree">
SELECT main.id_name, main.id
FROM sub 
</cfquery
<cfform name="studentForm" format="flash" width="1000" height="1000">
    <cftree name="courseTree" width="985" height="950" font="Arabic Transparent" fontsize="12.5">
    <cfloop query="getCourses">
    	 <cftreeitem value="#getCourses.id_name#"> 
         <cfquery name="getSubMenu" datasource="tree">
         	SELECT sub.id, sub.description
            FROM sub where sub.parent_id = #id#
         </cfquery>
		<cfif getSubMenu.id NEQ ''>
        	<cfloop query="getSubMenu">
            	<cftreeitem value="#getSubMenu.description#"  
       	 			parent="#getCourses.id_name#">
            </cfloop>
        </cfif>
    </cfloop>
</cftree>
</cfform>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Coast Line
Coast Line
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial