我正在使用 JSON 信息进行动态下拉。基本上它可以工作,但我不能将子菜单附加到父菜单。谁能给个好建议?
json:
"navigation":[
{
"title":"Home",
"link":"index.html"
},
{
"title":"Products",
"link":"product.html",
"subnav":[
{
"title":"Webapps",
"link":"products/webapps.html"
},
{
"title":"Mobile Apps",
"link":"products/mobile-apps.html"
}
]
}
]
我的功能:
var naviHandler = function (navi) {
var localNaviData = navi, ul = '<ul>',naviLink="";
$.map(localNaviData, function (val,i) {
naviLink +='<li>'
if(val.subnav){
naviLink += naviHandler(val.subnav)
}else{
naviLink +='<a href='+val.link+'>'+val.title+'</a>'
}
})
naviLink +='</li></ul>';
$('header').find('nav').append(naviLink);
}
naviHandler(localData[obj]);