JS递归算法遍历出树形菜单TreeMenu的Json格式数据

点击数:727

js递归算法遍历出树形菜单TreeMenu

本文地址http://yangjianyong.cn/?p=291转载无需经过作者本人授权

 //遍历出树形菜单json数据 start
        var getTreeMenu = function (menu, parentId = 0) {
            var tree = []
            jq(menu).each(function () {
                if (this.parent_id === parentId) {
                    var tmp = {}
                    tmp.menu_id = this.menu_id
                    tmp.name = this.get_menu.name
                    tmp.href = this.get_menu.href
                    tmp.children = getTreeMenu(menu, this.menu_id)
                    tree.push(tmp)
                }
            })
            return tree
        }
        //遍历出树形菜单json数据 start

欢迎来我的博客逛一逛 杨建勇的个人博客http://yangjianyong.cn

发表评论