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