重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

利用Freemarker怎么生成一个树形导航菜单

利用Freemarker怎么生成一个树形导航菜单?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

成都创新互联是一家专注于做网站、成都网站建设与策划设计,富川网站建设哪家好?成都创新互联做网站,专注于网站建设十年,网设计领域的专业建站公司;建站业务涵盖:富川等地区。富川做网站价格咨询:18980820575

很多导航菜单是树形的,即一级一级往下分,这样的结构固然需要用递归来处理。

对于Freemarker 来说,宏就相当于函数,其定义了签名及参数列表。

所以在freemarker页面应这样写:

<#macro menuTree menus> 
  <#if menus?? && menus?size gt 0> 
   <#list menus as menu> 
     
      
       
      
      
    
   ${menu.menuName!} 
    
      
      
     ${menu.url!} 
      
      
     ${menu.permissionText!} 
      
      
     ${menu.sortNo!} 
      
      
      [编辑] 
      
     
   <#if menu.menuBeans?? && menu.menuBeans?size gt 0> 
    <@menuTree menus = menu.menuBeans/> 
    
    
   
  
  
<@menuTree menus = dto /> 

后台数据:

[ 
 { 
  "id": 1, 
  "enable": true, 
  "remark": null, 
  "createBy": 1, 
  "createTime": 1503546411000, 
  "updateBy": 1, 
  "updateTime": 1503546415000, 
  "keyword": null, 
  "menuName": "系统管理", 
  "menuType": 1, 
  "parentId": null, 
  "iconcls": null, 
  "url": null, 
  "expand": null, 
  "sortNo": null, 
  "permission": null, 
  "moduleId": 1, 
  "parentName": null, 
  "leaf": 0, 
  "typeName": null, 
  "permissionText": null, 
  "menuBeans": [ 
   { 
    "id": 7, 
    "enable": true, 
    "remark": null, 
    "createBy": 1, 
    "createTime": 1503546411000, 
    "updateBy": 1, 
    "updateTime": 1503546415000, 
    "keyword": null, 
    "menuName": "模块管理", 
    "menuType": 1, 
    "parentId": 1, 
    "iconcls": null, 
    "url": "/module/list", 
    "expand": null, 
    "sortNo": null, 
    "permission": null, 
    "moduleId": 1, 
    "parentName": null, 
    "leaf": 1, 
    "typeName": null, 
    "permissionText": null, 
    "menuBeans": null 
   }, 
   { 
    "id": 3, 
    "enable": true, 
    "remark": null, 
    "createBy": 1, 
    "createTime": 1503546411000, 
    "updateBy": 1, 
    "updateTime": 1503546415000, 
    "keyword": null, 
    "menuName": "菜单管理", 
    "menuType": 1, 
    "parentId": 1, 
    "iconcls": null, 
    "url": "/menu/list", 
    "expand": null, 
    "sortNo": null, 
    "permission": "admin:add", 
    "moduleId": 1, 
    "parentName": null, 
    "leaf": 1, 
    "typeName": null, 
    "permissionText": null, 
    "menuBeans": null 
   } 
  ] 
 }, 
 { 
  "id": 2, 
  "enable": true, 
  "remark": null, 
  "createBy": 1, 
  "createTime": 1503546411000, 
  "updateBy": 1, 
  "updateTime": 1503546415000, 
  "keyword": null, 
  "menuName": "用户管理", 
  "menuType": 1, 
  "parentId": null, 
  "iconcls": null, 
  "url": null, 
  "expand": null, 
  "sortNo": null, 
  "permission": null, 
  "moduleId": 1, 
  "parentName": null, 
  "leaf": 0, 
  "typeName": null, 
  "permissionText": null, 
  "menuBeans": [ 
   { 
    "id": 9, 
    "enable": true, 
    "remark": null, 
    "createBy": 1, 
    "createTime": 1503546411000, 
    "updateBy": 1, 
    "updateTime": 1503546415000, 
    "keyword": null, 
    "menuName": "供应商管理", 
    "menuType": 1, 
    "parentId": 2, 
    "iconcls": null, 
    "url": null, 
    "expand": null, 
    "sortNo": null, 
    "permission": null, 
    "moduleId": 1, 
    "parentName": null, 
    "leaf": 1, 
    "typeName": null, 
    "permissionText": null, 
    "menuBeans": null 
   }, 
   { 
    "id": 8, 
    "enable": true, 
    "remark": null, 
    "createBy": 1, 
    "createTime": 1503546411000, 
    "updateBy": 1, 
    "updateTime": 1503546415000, 
    "keyword": null, 
    "menuName": "部门管理", 
    "menuType": 1, 
    "parentId": 2, 
    "iconcls": null, 
    "url": null, 
    "expand": null, 
    "sortNo": null, 
    "permission": null, 
    "moduleId": 1, 
    "parentName": null, 
    "leaf": 1, 
    "typeName": null, 
    "permissionText": null, 
    "menuBeans": null 
   }, 
   { 
    "id": 6, 
    "enable": true, 
    "remark": null, 
    "createBy": 1, 
    "createTime": 1503546411000, 
    "updateBy": 1, 
    "updateTime": 1503546415000, 
    "keyword": null, 
    "menuName": "权限管理", 
    "menuType": 1, 
    "parentId": 2, 
    "iconcls": null, 
    "url": "/user/list-6", 
    "expand": null, 
    "sortNo": null, 
    "permission": null, 
    "moduleId": 1, 
    "parentName": null, 
    "leaf": 1, 
    "typeName": null, 
    "permissionText": null, 
    "menuBeans": null 
   }, 
   { 
    "id": 5, 
    "enable": true, 
    "remark": null, 
    "createBy": 1, 
    "createTime": 1503546411000, 
    "updateBy": 1, 
    "updateTime": 1503546415000, 
    "keyword": null, 
    "menuName": "角色管理", 
    "menuType": 1, 
    "parentId": 2, 
    "iconcls": null, 
    "url": "/user/list-5", 
    "expand": null, 
    "sortNo": null, 
    "permission": null, 
    "moduleId": 1, 
    "parentName": null, 
    "leaf": 1, 
    "typeName": null, 
    "permissionText": null, 
    "menuBeans": null 
   }, 
   { 
    "id": 4, 
    "enable": true, 
    "remark": null, 
    "createBy": 1, 
    "createTime": 1503546411000, 
    "updateBy": 1, 
    "updateTime": 1503546415000, 
    "keyword": null, 
    "menuName": "分销商管理", 
    "menuType": 1, 
    "parentId": 2, 
    "iconcls": null, 
    "url": "/user/add-4", 
    "expand": null, 
    "sortNo": null, 
    "permission": null, 
    "moduleId": 1, 
    "parentName": null, 
    "leaf": 1, 
    "typeName": null, 
    "permissionText": null, 
    "menuBeans": null 
   }, 
   { 
    "id": 10, 
    "enable": true, 
    "remark": null, 
    "createBy": 1, 
    "createTime": 1503546411000, 
    "updateBy": 1, 
    "updateTime": 1503546415000, 
    "keyword": null, 
    "menuName": "员工管理", 
    "menuType": 1, 
    "parentId": 2, 
    "iconcls": null, 
    "url": null, 
    "expand": null, 
    "sortNo": null, 
    "permission": null, 
    "moduleId": 1, 
    "parentName": null, 
    "leaf": 1, 
    "typeName": null, 
    "permissionText": null, 
    "menuBeans": null 
   } 
  ] 
 } 
] 

关于利用Freemarker怎么生成一个树形导航菜单问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


标题名称:利用Freemarker怎么生成一个树形导航菜单
地址分享:http://cqcxhl.com/article/ijihop.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP