首页 > 解决方案 > 应用过滤器后同位素搜索功能停止工作

问题描述

所以我的代码有这个未知问题,一切似乎都运行良好;搜索有效,过滤器有效,但是当我在应用过滤器后尝试搜索时,它不再有效。

$('.select').on('click', '.filter-dropdown', function() {
    var parent = $(this).closest('.select');
    if (!parent.hasClass('is-open')) {
        parent.addClass('is-open');
        $('.select.is-open').not(parent).removeClass('is-open');
    } else {
        parent.removeClass('is-open');
    }
}).on('click', 'ul>li', function() {
    var parent = $(this).closest('.select');
    parent.removeClass('is-open').find('.filter-dropdown').text($(this).text());

    $('.filter-item').removeClass('active');
    $(this).addClass('active');
    var selector = $(this).attr('data-filter');

    $('.japps-container').isotope({
        filter: selector
    });
    return false;
});

var qsRegex;
var japps = $('.japps').isotope({
    // options
    itemSelector: '.japps-item',
    layoutMode: 'fitRows',
    filter: function() {
        var $this = $(this);
        var searchResult = qsRegex ? $this.text().match(qsRegex) : true;
        return searchResult;
    }
});

var $quicksearch = $('.filter-search').keyup(debounce(function() {
    qsRegex = new RegExp($quicksearch.val(), 'gi');
    japps.isotope();
}, 1));

function debounce(fn, threshold) {
    var timeout;
    threshold = threshold || 100;
    return function debounced() {
        clearTimeout(timeout);
        var args = arguments;
        var _this = this;

        function delayed() {
            fn.apply(_this, args);
        }
        timeout = setTimeout(delayed, threshold);
    };
}

请参阅下面的 CodePen 链接以查看完整代码。

代码:https ://codepen.io/bonafideboss/pen/oNeyMbQ

我找不到问题。请指教。提前致谢。

标签: javascripthtmljqueryjquery-isotope

解决方案


推荐阅读