如何仅使用jQuery / JSON构建以下导航菜单?
我的JSON如下;
{
"general":{
"logo":"assets/images/logo.png",
"name" : "Company Name"
},
"navigation":[
{
"title":"Home",
"link":"index.html"
},
{
"title":"Products",
"link":"product.html",
"subnav":[
{
"title":"Webapps",
"link":"products/w.html"
},
{
"title":"Mobile Apps",
"link":"products/m.html"
}
]
}
]
}
我会避免除了jQuery以外的任何事情。
答案 0 :(得分:1)
如果您的问题只是遍历json ..这可能会有所帮助。
for (i in jar.navigation) {
alert(jar.navigation[i].title);
var hassub = (jar.navigation[i].subnav != null);
if (hassub) {
for (j in jar.navigation[i].subnav) {
alert(jar.navigation[i].subnav[j].title);
}}
}