以下のいくつかの JQuery メソッドを使用しており、Web ページのパフォーマンスを向上させるためにそれらを純粋な JavaScript に変換したいと考えています。
$(function() {
$('#resultDetails').on('click', '.toggle', function() {
var findChildren = function(tr) {
var depth = tr.data('depth');
return tr.nextUntil($('tr').filter(function() {
return $(this).data('depth') <= depth;
}));
};
var el = $(this);
var tr = el.closest('tr');
var children = findChildren(tr);
var subnodes = children.filter('.expand');
subnodes.each(function() {
var subnode = $(this);
var subnodeChildren = findChildren(subnode);
children = children.not(subnodeChildren);
});
if(tr.hasClass('collapse')) {
tr.removeClass('collapse').addClass('expand');
children.hide();
} else {
tr.removeClass('expand').addClass('collapse');
children.show();
}
return children;
});
});
$(document).ready(function() {
$('table tr').on('click', function() {
$('#showContent').html($(this).find('.content').html());
});
$('table th').on('click', function() {
$('#showContent').html($(this).find('.content').html());
});
$('#resultDetails tbody tr').on('click', function(event) {
$(this).addClass('highlight').siblings().removeClass('highlight');
});
});
デモはhttp://jsfiddle.net/wYmwT/1/にあります。テーブルに 2000 行を超える行が含まれている場合、読み込みに時間がかかります。
助けはありますか?