The fastest will look something like this:
var oldTable = document.getElementById('example'),
newTable = oldTable.cloneNode(true);
for(var i = 0; i < json_example.length; i++){
var tr = document.createElement('tr');
for(var j = 0; j < json_example[i].length; j++){
var td = document.createElement('td');
td.appendChild(document.createTextNode(json_example[i][j]));
tr.appendChild(td);
}
newTable.appendChild(tr);
}
oldTable.parentNode.replaceChild(newTable, oldTable);
And should run in milliseconds. Here is an example: http://jsfiddle.net/Paulpro/YhQEC/ It creates 200 table rows each containing 10 td's.
You want to append using elements, not strings, but you don't want to append anything to the DOM until you're done creating the entire structure (to avoid reflow in your loop). So you can clone the original table and append to the clone, then insert the clone after your loop completes.
You will also gain a fair bit of speed by avoiding jQuery and interacting with the DOM directly.
Your code may look like:
var oldTable = document.getElementById('content_table'),
newTable = oldTable.cloneNode(true),
tr, td;
for(var i = 0; i < entries.alumnus.length.length; i++){
tr = document.createElement('tr');
tr.id = 'entry' + i;
tr.className = 'entry';
if(entries.alumnus[i].title){
td = document.createElement('td');
td.id = 'title' + i;
td.className = 'cell';
var span = document.createElement('span');
span.className = 'content';
span.appendChild(document.createTextNode(entries.alumnus[i].title);
td.appendChild(span);
tr.appendChild(td);
tr.appendChild(createFiller(filler));
}
// REST OF ELEMENTS
newTable.appendChild(tr);
}
oldTable.parentNode.replaceChild(newTable, oldTable);
function createFiller(filler){
var td = document.createElement('td');
td.style.width = '5%';
td.appendChild(document.createTextNode(filler);
return td;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…