【问题标题】:OpenCart filter: Clear old selectionOpenCart 过滤器:清除旧选择
【发布时间】:2017-09-08 15:01:12
【问题描述】:

我一直在尝试这样做,但我不知道该做什么了。我正在使用 OpenCart 版本 2.3.0.2 。不知何故,过滤器无法正常工作。

我第一次选择过滤器没问题。但是如果我删除 2 个过滤器并添加一个新过滤器,旧的过滤器将保留在 URL 中。

这会将过滤器 ID 添加到 URL:

$('#button-filter').on('click', function() {
    filter = [];    
    $('input[name^=\'filter\']:checked').each(function(element) {
        filter.push(this.value);
    });
    location = '<?php echo $action; ?>&filter=' + filter.join(',');
});

这个清除过滤器id:

$('#button-filterclear').on('click', function() {
  filter = [];  
  $('input[name^=\'filter\']:checked').each(function(element) {
    filter.push(this.value);
  });
  location = '<?php echo $action; ?>&filter=';
});

我需要第一个按钮清除,然后添加新的过滤器 id。

【问题讨论】:

    标签: jquery filter opencart opencart2.x


    【解决方案1】:

    首先,清除过滤器的方法是错误的:

    $('#button-filterclear').on('click', function() {
        // NOT USED: filter = [];
        // NOT USED: $('input[name^=\'filter\']:checked').each(function(element) {
        // NOT USED:     filter.push(this.value);
        // NOT USED: });
        location = '<?php echo $action; ?>&filter=';
    });
    

    可能保留过滤器选择的唯一原因是您的父 form 元素没有 autocomplete="off"。添加属性应该没问题。

    【讨论】:

      【解决方案2】:

      在链接的点击事件上使用:-

      在每个点击函数里面:-

      添加 window.location.href=?page=1&productName=this 等

      【讨论】:

        【解决方案3】:

        感谢您的回答,但它不起作用。

        问题仍然存在。观看网址,它不会删除旧查询:

        /index.php?route=product/category&path=59&filter=35,36,31,32

        Id 35 和 36 是前两个 fitler。然后我删除了 thoose 并添加了 31 和 32 但保留在 url 中。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-03-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-06-19
          • 2020-12-30
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多