【问题标题】:List.js Dropdown Filter - How to reset to initial state?List.js 下拉过滤器 - 如何重置为初始状态?
【发布时间】:2018-07-24 07:40:45
【问题描述】:

我的下拉过滤器工作正常,但我想提供一个 All 值来刷新列表项并显示初始状态(所有列表项都可见)。

我有一个 onClick 按钮:

$('#filter-clear').click(function() {
  featureList.filter();
  return false;
});

下面下拉代码中的 if 语句未按预期工作。 基本上,如果选择值为 ALL,我想运行与过滤清除按钮运行相同的功能(显示所有项目)。否则返回具有所选值的项目。

这是一个下拉菜单的代码笔,没有以下 if 语句:https://codepen.io/nolaandy/pen/Zryaoq

我的下拉代码:

$('#positionChange').change(function () {
var selection = this.value; 
var option=document.getElementById('positionChange').value;
console.log(selection);console.log(option);

featureList.filter(function (item) {
  if (selection='ALL') {
      featureList.filter();
      } else {
return (item.values().playerPosition == selection);
}
});

});

【问题讨论】:

    标签: jquery html list.js


    【解决方案1】:

    试试这个代码

    $('#positionChange').change(function () {
    var selection = this.value; 
    var option=document.getElementById('positionChange').value;
    console.log(selection);console.log(option);
    if(selection != 'ALL')
        featureList.filter();
    else
        featureList.filter(function (item) {
            return (item.values().playerPosition == selection);
        });
    
    });
    

    if/else 在函数过滤器内部是不好的,最好在外面做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 2017-05-12
      • 1970-01-01
      • 1970-01-01
      • 2023-01-27
      • 2021-01-15
      • 2015-05-20
      相关资源
      最近更新 更多