I have a nested loop which creates a drop down with 3 levels. Works fine on modern browsers but on IE8 it hangs and takes several seconds when theres even a moderate volume of data.
It creates a list of publishers, when i click a publisher i get that publishers authors, click an author i get the years they're published.
I'm looking for a way of optimizing this to reduce the time it takes to run in IE.
Any ideas?
function createDropDown() {
var target = $('#dropdownMenu');
for (var i = 0; i < data.genres.length; i++) {
var genreval = data.genres[i].genre;
for (var j = 0; j < data.genres[i].publishers.length; j++) {
var publisherval = data.genres[i].publishers[j].publisher;
if (typeof app.cache.publisher[publisherval] == 'undefined') {
target.append('<li class="publisher" data-value="' + publisherval + '"><a href="#" class="nextmenu">' + publisherval + '</a><ul class="sub-menu" data-title="publishers"></ul></li>');
app.cache.publisher[publisherval] = {
'ul': target.find('>.publisher[data-value="' + publisherval + '"]>.sub-menu'),
'author': {}
};
}
var ulauthors = app.cache.publisher[publisherval].ul;
for (var k = 0; k < data.genres[i].publishers[j].authors.length; k++) {
var authorval = data.genres[i].publishers[j].authors[k].author + ' (' + genreval + ')';
var author_val = data.genres[i].publishers[j].authors[k].author;
var originalgenre = data.genres[i].publishers[j].authors[k].originalgenre;
if (typeof app.cache.publisher[publisherval].author[authorval] == 'undefined') {
ulauthors.append('<li class="author" data-value="' + authorval + '"><a href="#" class="nextmenu">' + authorval + '</a><ul class="sub-menu" data-title="authors"></ul></li>');
app.cache.publisher[publisherval].author[authorval] = ulauthors.find('>.author[data-value="' + authorval + '"]>.sub-menu');
}
var ulyears = app.cache.publisher[publisherval].author[authorval];
var gItems = "";
for (var m = 0; m < data.genres[i].publishers[j].authors[k].authorYears.length; m++) {
var yearval = data.genres[i].publishers[j].authors[k].authorYears[m];
var year = ulyears.find('.year[data-value="' + yearval + '"]');
if (year.size() == 0) {
var id = ++count;
gItems+='<li class="year" data-value="' + yearval + '"><a id="selyear' + id + '" class="addItem" data-id="' + id + '" data-originalgenre ="' + originalgenre + '"data-year="' + yearval + '" data-publisher="' + publisherval + '" data-author="' + author_val '">' + yearval + '</a></li>';
}
}
ulyears.append(gItems);
};
};
};
}