列出其父级下的子菜单项

时间:2014-05-30 12:03:57

标签: mysql coldfusion coldfusion-9

我有一个包含多个列的表,如下所示:

id  parent__id  title  body  navdepth  navorder navitem
1    0          home    xx      0         1       1
2    1          about   xx      1         2       1
3    2          child   xx      2         1       1
4    3          subchild x      3         1       1

我正在查询这样的表格以获得导航标题。

<cfquery name="getnavigation">
  SELECT
    c1.id,
    c1.title,
    c1.parent__id,
    c1.nav_depth,
    c1.nav_order
  FROM content AS c1

  LEFT JOIN content AS c2
  ON c1.id = c2.parent__id
  WHERE 0 = 0
  AND c1.is_nav_item = 1
  GROUP BY c1.id
  ORDER BY c1.nav_depth, c1.nav_order
</cfquery>

我希望将nav_depth 0到1的页面显示为父页面,以防任何页面在下拉列表中列出子项。

我试过这个,但它显示所有页面为父:

<div class="nav-collapse collapse" role="navigation">                                     
  <ul class="nav top-2">
    <cfset local.level1 = -1 />
    <cfset local.level2 = -1 />
    <cfloop query="navigation">
        <cfset local.level2 = navigation.nav_depth>
    <cfif local.level2 GT local.level1>
      <li><a href="#buildUrl(navigation.title)#" class="<cfif local.level1 EQ -1><cfelse>dropdown-toggle" data-toggle="dropdown</cfif>">#navigation.title#</a>                 
      <cfelseif local.level2 LT local.level1>
      <cfset local.temp = local.level1 />
      <cfloop condition="local.temp GT local.level2">
        </li>
        <cfset local.temp -= 1 />
      </cfloop>
      </li><li><a href="#buildUrl(navigation.title)#">#navigation.title#</a>
    <cfelse>
      </li><li><a href="#buildUrl(navigation.title)#">#navigation.title#</a>                        
    </cfif>
    <cfset local.level1 = navigation.nav_depth />
    </cfloop>
    <cfset local.temp = local.level1 />
    <cfloop condition="local.temp GT 0">
        </li>
    <cfset local.temp -= 1 />
    </cfloop>
  </ul>
</div><!-- /nav-collapse -->

有没有办法在其父级下显示子项目?

0 个答案:

没有答案