【发布时间】:2010-11-01 19:02:37
【问题描述】:
我有一张桌子,我做了排序。它的执行时间不好。我猜这是因为 DOM 操作。 /* 我正在转换为数组 */
var rows = $table.find('tbody > tr').get();
$.each(rows, function(index, row){ /*then again to 2D array */
if(($(row).children('td').eq(0).attr('class').indexOf('collapse') != -1 || $(row).children('td').eq(0).attr('class').indexOf('expand') != -1)){
myData.push(myData1);
myData1 = [];
}
myData1.push(row);
rowCount++;
if(rowCount == $(rows).length){ // to assign last group of rows
myData.push(myData1);
myData1 = [];
}
});
这是直接通过数组选择DOM元素的最佳方式。因为我用了很多次。
【问题讨论】: