I have two elements on my page:
<ul id="VerticalMenu></ul>
<ul id="AccordionMenu"></ul>
I'm calling some JSON with jQuery and loading elements in the divs. I'm curious if there are things I can be doing more efficiently, better ways to use selectors and JSON. Here's a huge pile of jquery, thanks for any help:
$().ready(function() {
//Load sections
GetCarlineSections(_BucketID);
});
function GetCarlineSections(bucketID) {
//Get section json list
$.ajax(
{
type: "POST",
url: _ApplicationRootURL + 'GetChildBucketList', //Call the ActionResult to return the JSON object
data: 'parentID=' + bucketID,
success: function (sections) { //'sections' is an array of JSON objects returned by GetChildBucketList
$(sections).each(function () {
$('#VerticalMenu') //Append each item to the #VerticalMenu <ul>
.append(
$('<li/>') //Append a new <li> element to <ul> #VerticalMenu
.addClass('Section')
.html(
$('<h4/>') //Create a new <h4> inside of the <li>
.addClass(this.BucketName)
.html(this.BucketName)
.click({ parentID: this.BucketID }, function (event) { //Attach a click event to the <h4> element
$('#AccordionMenu').empty();
GetSectionSubSections(event.data.parentID); //Event.data.parentID is the id of the bucket represented by this <h4> element
})
)
);
});
}
});
}
function GetSectionSubSections(bucketID) {
$.ajax(
{
type: "POST",
url: _ApplicationRootURL + 'GetChildBucketList',
data: 'parentID=' + bucketID,
success: function (SubSections) { //SubSections are the children buckets of Section, local var bucketID
$(SubSections).each(function () {
$('#AccordionMenu')
.append(
$('<li/>')
.addClass('SubSection')
.html(
$('<h4/>')
.addClass(this.SEOURLName)
.html(this.BucketName)
.click({ parentID: this.BucketID }, function (event) { //Eventdata parentID passes the SubSectionID to the event object
GetSubSectionHeadlines(this, event.data.parentID)
})
)
);
});
}
});
}
function GetSubSectionHeadlines(parentElement, SubSectionID) {
//Get the Headlines based on the parent SubSection
$(parentElement).after($('<ul/>').addClass(parentElement.className));
$.ajax({
type: 'POST',
url: _ApplicationRootURL + 'GetChildBucketList',
data: 'parentID=' + SubSectionID,
success: function (Headlines) {
$(Headlines).each(function () {
$('ul.' + parentElement.className).prepend(
$('<li/>')
.html(this.BucketName)
)
})
}
});
}