1

最后一点需要帮助...

这里有一个小提琴...

我通过按钮单击过滤搜索,并按关键字搜索。他们独立工作,但我似乎无法让他们一起工作。

我认为这个功能在这里的某个地方,但我有点迷失了......

function isotopeSearch(kwd)
{
    // reset results arrays
    var matches = [];
    var misses = [];

    $('.item').removeClass('match miss'); // get rid of any existing classes
    $('#noMatches').hide(); // ensure this is always hidden when we start a new query

    if ( (kwd != '') && (kwd.length >= 2) ) { // min 2 chars to execute query:

        // loop through brands array        
        _.each(items, function(item){
            if ( item.first.indexOf(kwd) !== -1 ) { // keyword matches element
                matches.push( $('#'+item.id)[0] );
            } else {
                misses.push( $('#'+item.id)[0] );
            }
        });

        // add appropriate classes and call isotope.filter
        $(matches).addClass('match');
        $(misses).addClass('miss');
        $container.isotope({ filter: $(matches) }); // isotope.filter will take a jQuery object instead of a class first as an argument - sweet!

        if (matches.length == 0) {
            $('#noMatches').show(); // deal with empty results set
        }

    } else {
        // show all if keyword less than 2 chars
        $container.isotope({ filter: '.item' });
    }

}

编辑:我试图让它只能按名字/姓氏搜索。

4

1 回答 1

0

基本上看起来您的"*"选择器导致了几个All按钮的问题。如果您只是将它们设为空白“”,它似乎可以工作。

我将此警报放入您的代码中,并注意到选择器在进行了几次选择后变得有些奇怪:

    var selector = isoFilters.join('');
    alert(selector);

你结束了像这样的选择器**.ar

JSFiddle在这里:http: //jsfiddle.net/TrueBlueAussie/2pasq/14/

没有一套完整的项目值来测试所有组合,但如果你去掉两个“*”过滤器,它似乎可以工作。

于 2013-09-17T17:45:10.407 回答