首頁 > web前端 > js教程 > Freemarker 產生樹狀導覽功能表的方法

Freemarker 產生樹狀導覽功能表的方法

一个新手
發布: 2017-09-20 09:19:08
原創
1725 人瀏覽過

許多導覽選單是樹狀的,也就是一級一級往下分,這樣的結構固然需要用遞迴來處理。 
對Freemarker 來說,巨集相當於函數,其定義了簽章及參數清單。

所以在freemarker頁面要這樣寫:

#
        <#macro menuTree menus>
            <#if menus?? && menus?size gt 0>
                <#list menus as menu>
                    <tr>
                        <td>
                            <input type="checkbox" name="ids" value="${menu.id}" />
                        </td>
                        <td>
                <span title="${menu.name!}" style="margin-left: ${menu.leaf * 30}px;[#if menu.leaf == 0] color: #000000;[/#if]">
                ${menu.menuName!}
                </span>
                        </td>
                        <td>
                        ${menu.url!}
                        </td>
                        <td>
                        ${menu.permissionText!}
                        </td>
                        <td>
                        ${menu.sortNo!}
                        </td>
                        <td>
                            <a href="edit.jhtml?id=${menu.id}">[编辑]</a>
                        </td>
                    </tr>
                <#if menu.menuBeans?? && menu.menuBeans?size gt 0>
                    <@menuTree menus = menu.menuBeans/>
                </#if>
                </#list>
            </#if>
        </#macro>
        <!-- 调用宏 生成递归树 -->
    <@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 產生樹狀導覽功能表的方法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板