遞歸遍歷多層次菜單

//根據後臺數據格式化菜單
function formatMenu(data) {
    return data.map(function (item) {
        if (!item) {
            return null;
        }
        var path = item.path, name = item.menuName, id = item.id;

        var result = {
            path: path,
            name: name,
            id: id
        };

        if (item.pid > 0) {
            result.exact = true;
        }
        if (item.ch) {
            var children = formatMenu(item.ch);
            result.children = children;
        }
        return result;
    }).filter(function (item) {
        return item
    });
}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章