Use the Freemarker macro to define a display using a tree-shaped catalog

Source: Internet
Author: User

Use the Freemarker macro to define a display using a tree-shaped catalog

1, the effect shows as follows


2. Front-end Code
<div class= "Kcmenu" >    <div class= "Sidebar-wrapper"  id= " Sidebar-wrapper ">        <div class=" title "><span  class= "Pull-left ti-arrow-circle-left" ></span> Course catalogue </div>         <div id= "Moremenu" >             <ul class= "Kcnav" >                 <li><a style= "Cursor: pointer"  onclick= " Searchcoursebycatalogid (' 0 ') > All courses </a></li>                 [#list  cataloglist?sort_by ("Catalogorderno")  as  catalog]                     <li>                         <a style= "Cursor: pointer"  [#if  !catalog.soncatalogs??  | |  catalog.soncatalogs?size == 0]onclick= "Searchcoursebycatalogid (' ${catalog.catalogId} ')" [/#if] >${catalog.catalogName}</a>                         [#if  catalog.soncatalogs??  && catalog.sonCatalogs?size > 0]                         <ul >                             [@showCatalogTree  catalog /]        &nBsp;                </ul >                         [/#if]                     </li>                 [/#list]             </ul>        </div>     </div></div>

3, Freemarker macro definition
[#macro  coursecenterbreadcrumb breadcrumbcataloglist]    <ol class=] breadcrumb ">        <li><a href=" > Home </a> </li>        [#if  breadcrumbcataloglist?size == 0 ]            <li><a href= "/lrm/ Controller/coursecenter/search " style=" color:  #417cf2; " > Course Center </a></li>        [#else]             <li><a href= "/lrm/controller/coursecenter/search "> Course Center </a></li>        [/#if]         [#list  breadcrumbCatalogList as catalog]             [#if &NBSP;CATALOG_HAS_NEXT]&NBSp;               <li><a  style= "Cursor: pointer"  onclick= "Searchcoursebycatalogid (' ${catalog.catalogid} ')" >${ catalog.catalogname}</a></li>             [#else]                 <li><a style= "cursor: pointer;color:  #417cf2;"  onclick= "Searchcoursebycatalogid (' ${catalog.catalogid} ')" >${catalog.catalogName}</a></li>             [/#if]         [/#list]    </ol>[/#macro]


4, the data is recursive in the definition of macro, so the back-end data should be organized well.

map<string,string> catalogconditionmap  = new hashmap (); Catalogconditionmap.put ("CompanyID",  webusersession.getcorpid ()); List<catalog> cataloglist = catalogservice.get (CATALOGCONDITIONMAP,&NBSP;ORDER.ASC (" Catalog_order_no ")); Iterator<catalog> iterator = cataloglist.iterator ();while  ( Iterator.hasnext ())  {    catalog catalog = iterator.next ();     if (Catalog.getparentcatalogid (). Equals ("")  | |  catalog.getparentcatalogid (). Equals ("0"))  {         Setcatalogchildren (Catalog, webusersession.getcorpid ());    } else {         iterator.remove ();     }}modelmap.put (" CatalogList ",  cataloglist); 
private void Setcatalogchildren (Catalog catalog,string companyid) {list<catalog> soncataloglist = CatalogService    . Getbyparentid (Catalog.getcatalogid (), CompanyID);        if (Collectionutils.isnotempty (soncataloglist)) {catalog.setsoncatalogs (soncataloglist);        for (Catalog soncatalog:soncataloglist) {Setcatalogchildren (Soncatalog, CompanyID); }    }}


Organizes the directory tree structure into a tree form.



Use the Freemarker macro to define a display using a tree-shaped catalog

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.