简体   繁体   English

使用Hash或GET参数初始化jQuery过滤器

[英]initialize jQuery filter using Hash or GET-parameters

UPDATE 更新
Due to low activity on my original question (below) I rephrase it simply like this: 由于我的原始问题(如下)的活动较少,因此我将其改写为:
How can I initialize MIXITUP jQuery filter from other url using Hash or GET-parameters? 如何使用哈希或GET参数从其他网址初始化MIXITUP jQuery过滤器


==== ====

I am using MIXITUP jQuery filter for sorting several elements on one page. 我正在使用MIXITUP jQuery过滤器在一页上对几个元素进行排序。 Is there a way to make a link from another page with one of the filers already active? 有没有一种方法可以使另一个页面链接到一个已激活的文件管理器?
The idea is to have one link for each category and also one main link for the hole page. 这个想法是为每个category一个链接,为孔页面提供一个main链接。 The category link would land the visitor on the second page with the selected category filter already activated. 类别链接会将访问者登陆到第二页,并且已激活selected category过滤器。 If the visitor would choose the main link he would land on the page with all categories visible. 如果访问者选择main链接,则他将进入显示all categories的页面。 For example lets say I sell cables and want to have a link from index to store with HDMI activated, so that when the jump has been made the visitor lands on the store page and only sees HDMI cables, with the option of selecting other filters to see the rest of the products of course. 例如,假设我出售电缆,并且希望在激活HDMI的情况下建立从indexstore的链接,以便在进行跳转后,访问者登陆store页面并仅看到HDMI电缆,并且可以选择其他过滤器来当然可以看到其余产品。
Please ask if you need more information, sample code or anything else.. 请询问您是否需要更多信息,示例代码或其他信息。

Thanks in advance 提前致谢

You can specify the filter which will take effect right when the page is loaded by using the load.filter setting like this: 您可以使用以下load.filter设置指定将在页面加载后立即生效的过滤器:

$('#container').mixItUp({
  load: {
    filter: 'your filter'
  }
});

Nothing stops you from getting the value for this setting from document.location.hash property . 没有什么可以阻止您从document.location.hash属性获取此设置的值。 You can check whether the hash is empty, and if it's not, use its value as a filter: 您可以检查哈希是否为空,如果不是,则将其值用作过滤器:

$('#container').mixItUp({
  load: {
    filter: document.location.hash == '' ? 'all' :
      ('.' + document.location.hash.substring(1))
  }
});

hash.substring(1) is needed because the string would include the # character itself, and I append . hash.substring(1)是必需的,因为字符串本身将包含#字符,并且我追加了. in the beginning because I think it's likely that you want to always filter by class and there's no need to include the dot in the URL. 一开始是因为我认为您可能希望始终按类进行过滤,并且不需要在URL中包含点。

Demo on CodePen: 在CodePen上进行演示:

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

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