菜单支持三组,所以 服务哭可定义一个三维数组的json数据返回,以下以PHP的数组来说明
~~~php
$menu = [
[ "id"=>1, "url"=>"", "name"=>"内容管理","iconfont"=>"","sub"=>
[
["id"=>5, "url"=>"", "name"=>"内容管理","iconfont"=>"","sub"=>
[
["id"=>6, "url"=>"article.html", "name"=>"文章列表","iconfont"=>""],
["id"=>7, "url"=>"article-cat.html", "name"=>"文章分类","iconfont"=>""],
["id"=>8, "url"=>"tag.html", "name"=>"标签管理","iconfont"=>""]
]
]
]
],
[ "id"=>2, "url"=>"", "name"=>"产品管理","iconfont"=>"","sub"=>
[
["id"=>9, "url"=>"product.html", "name"=>"产品列表","iconfont"=>"","sub"=>[]],
["id"=>10, "url"=>"brand.html", "name"=>"品牌管理","iconfont"=>"","sub"=>[]],
["id"=>11, "url"=>"product-cat.html", "name"=>"分类管理","iconfont"=>"","sub"=>[]]
]
]
]
~~~
返回的格式
~~~php
$msg['data']['list'] = $menu;
$msg['status']=200;
echo header("content-type:text/html; charset=utf-8");
echo json_encode($msg);
~~~
最终的json数据
~~~json
{
"data": {
"list": [{
"id": 1,
"url": "",
"name": "内容管理",
"iconfont": "",
"sub": [{
"id": 5,
"url": "",
"name": "内容管理",
"iconfont": "",
"sub": [{
"id": 6,
"url": "article.html",
"name": "文章列表",
"iconfont": ""
},
{
"id": 7,
"url": "article-cat.html",
"name": "文章分类",
"iconfont": ""
},
{
"id": 8,
"url": "tag.html",
"name": "标签管理",
"iconfont": ""
}
]
}]
},
{
"id": 2,
"url": "",
"name": "产品管理",
"iconfont": "",
"sub": [{
"id": 9,
"url": "product.html",
"name": "产品列表",
"iconfont": "",
"sub": []
},
{
"id": 10,
"url": "brand.html",
"name": "品牌管理",
"iconfont": "",
"sub": []
},
{
"id": 11,
"url": "product-cat.html",
"name": "分类管理",
"iconfont": "",
"sub": []
}
]
},
]
},
"status": 200
}
~~~