简体   繁体   English

同位素-通过关键字和搜索组合过滤器

[英]Isotope - combining filter by keyword and search

I'm trying to combine a filter by search and a filter by keyword with Isotope. 我正在尝试通过同位素将过滤器和关键字过滤器组合在一起。 For the search filter I based my code on http://codepen.io/desandro/pen/wfaGu 对于搜索过滤器,我的代码基于http://codepen.io/desandro/pen/wfaGu

You can see my code on http://fiddle.jshell.net/8DJ8V/ 您可以在http://fiddle.jshell.net/8DJ8V/上看到我的代码

At the point I'm at now, it works if you start with a search then use filters. 就目前而言,如果您先进行搜索然后使用过滤器,那么它就可以正常工作。 But if the user starts using filters, then tries to search, the search won't work. 但是,如果用户开始使用过滤器,然后尝试搜索,则搜索将无法进行。 Probably something wrong in the order I've placed the functions and/or trying to initialize Isotope twice - but I can't get around to it. 我放置函数和/或尝试两次初始化同位素的顺序可能出了点问题,但是我无法解决它。

Any idea? 任何想法?

The keyup function call the function $container.isotope() again and when you click in some button, the filter gets lost. keyup函数再次调用$ container.isotope()函数,当您单击某个按钮时,过滤器将丢失。

So I made some changes in your code: http://fiddle.jshell.net/lucaspedroza/7t8mgont/ 因此,我对您的代码进行了一些更改: http : //fiddle.jshell.net/lucaspedroza/7t8mgont/

On line 32, I add the filter function: 在第32行,我添加了filter函数:

$container.isotope({
    filter: function() {
      return qsRegex ? $(this).text().match( qsRegex ) : '.active';
    },
  });
}, 200 ) );

And clean the input when use the filter so there is no confusion about which filter is being used. 并在使用过滤器时清洁输入,以免混淆正在使用哪个过滤器。

I hope I have help you. 希望对您有帮助。

Regards. 问候。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM