title: bad code warning: grouping an array for nested a menu
body: <p>Wow. I have been asked to add a 3rd level to a tree menu for a company. Below is what I found had created about 6 months ago. And while it works, there is no way I am going to add another cfloop hack to it. All my feelings tell me this just bad code and to redo.</p>
  
  <p>I cannot change the databased nor have the results returned in anything else other than a query. now you know the way it has to be, what are my options here???</p>
  
  <p>Each record in the DB has NO relationship, the code below just looks at the name of the widget and works out if it is a parent or not based on the :</p>
  
  <p>examples of widgetName</p>
  
  <p>1=  Compliance:</p>
  
  <p>2=  Compliance: Document Library:</p>
  
  <p>3= Compliance: Document Library: All Firms</p>
  
  <p>so above says that widget 2 should be 2 levels down. look at the code you will see in a very bad way what has been done....</p>
  
  <pre><code>&lt;cfoutput&gt;
  
  &lt;ul id="root" class="menu"&gt;     
  
       &lt;cfloop array="#rc.widgets.getPageRecords()#" index="local.widgets"&gt;
  
  
           &lt;cfif listLen(local.widgets.getwidgetName(),":") eq 1&gt;
            &lt;li&gt;
  
              &lt;a href='javascript:void(0);' childid = '#local.widgets.getwidgetID()#' class='cat_close category'&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/a&gt;
              &lt;a href='javascript:void(0);'&gt;#local.widgets.getwidgetName()# - #listLen(local.widgets.getwidgetName(),":")#&lt;/li&gt;&lt;/a&gt;
              &lt;cfset wordToFind = local.widgets.getwidgetName()&gt;
              &lt;ul id='#local.widgets.getwidgetID()#'&gt;
                   &lt;cfloop array="#rc.widgets.getPageRecords()#" index="local.widgets"&gt;
                       &lt;cfif listLen(local.widgets.getwidgetName(),":") eq 2 AND  #find(wordToFind,local.widgets.getwidgetName())#&gt;
                          &lt;li&gt;
                              &lt;a href='javascript:void(0);' childid = '#local.widgets.getwidgetID()#' class='cat_close category'&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/a&gt;
                              &lt;a href='javascript:void(0);'&gt;#local.widgets.getwidgetName()# - #listLen(local.widgets.getwidgetName(),":")#&lt;/li&gt;&lt;/a&gt;
                          &lt;/li&gt;
                       &lt;/cfif&gt;
                   &lt;/cfloop&gt;
              &lt;/ul&gt;
           &lt;/cfif&gt;
  
  
       &lt;/cfloop&gt;
  
  
  
  &lt;/ul&gt;
  &lt;/cfoutput&gt;
  </code></pre>