我有一个名为refreshHistory()的方法,它基本读取本地存储的json列表(使用https://github.com/marcuswestin/store.js/),并按照它们的存储顺序填充列表。jQuery:重复调用时重绘函数极其缓慢
每次发生用户操作时,都会调用此方法。但是随着列表越来越大,它会拖慢浏览器爬行。
function refreshHistory() {
var records = typeof store.get('history') == "undefined" ? 0 : store.get('history').history;
;
if (records == 0) {
$('#content #historyView').html('<i>history show up here in order.</i>');
} else {
var xhistory = '<div id="history">';
for (var i = 0; i < records.length; i++) {
var xaction = records[i]
xhistory += '<div id="action">' + (i + 1) + '. ' + '<b>' + xaction.action + "</b> " + xaction.caption + '<span class="delaction" id=' + i + ' data-stamp="' + xaction.msg + '" style="color:red;cursor:pointer;">' + '[remove]' + '</span></div>'
}
xhistory += "</div>"
$('#qtip-0-content #historyView').html(xhistory);
}
}
我建议用你的问题的简化版本创建一个[jsfiddle](http://jsfiddle.com),这样其他人可以给你更具体的反馈。 – OlliM 2014-10-28 10:44:55