我正在对超过 10000 行数据集进行实时搜索。我已经提到了可用的 dom 结构。尽管我尝试在一次输入后对每个结果进行实时搜索检查,但我的浏览器正在挂起。有没有其他有效的方法可以降低它的复杂性。
<label class="label">
<input type="checkbox" name="123" value="">
</label>
<label class="label">
<input type="checkbox" name="123" value=" General AUX"> General AUX
</label>
<label class="label">
<input type="checkbox" name="123" value=" Annser"> Annser
</label>
<label class="label">
<input type="checkbox" name="123" value=" LRIPL"> LRIPL
</label>
<label class="label">
<input type="checkbox" name="123" value=" Soy Impulse"> Soy Impulse
</label>
** 是的,针对 DOM 进行实时搜索** JS 代码,我用于实时搜索
$(".form-container #filter").keyup(function() {
var filter = $(this).val(),
count = 0;
if(filter.length>=2){
// Loop through the comment list
$(".label").each(function() {
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).fadeOut();
// Show the list item if the phrase matches and increase the count by 1
} else {
$(this).show();
count++;
}
});
// Update the count
var numberItems = count;
// $(".popopup-header").text(count + " results");
//$("#filter-count").text(count + "results");
}
});