creating list with sub items from json structure
JavaScript
var myList = [{
"title": "Home",
"sub": 0,
"url": "/home",
"show": 1
}, {
"title": "News",
"sub": 0,
"url": "/news",
"show": 1
}, {
"title": "About",
"sub": 1,
"url": "/about",
"show": 1,
child: [{
"title": "Contact",
"sub": 0,
"url": "/about/contact",
"show": 1
}]
}, {
"title": "Other",
"sub": 0,
"url": "/other",
"show": 0
}];
$.each(myList, function (entryIndex, entry) {
var title = this.title;
var show = "";
var sub = '';
var url = this.url;
if (!this.show) {
show = "style=color:grey;";
}
console.log(this.sub);
console.log(this.child);
if (this.sub) {
sub = $("ul").append(this.child[0].title);
console.log(sub);
}
$("ul").append("<li " + show + "> " + title + sub + "</li>");
});