【发布时间】:2011-12-14 18:31:46
【问题描述】:
我目前正在使用 Isotope 过滤出版物列表,但希望能够将标准的、记录在案的链接过滤器方法与选择元素结合起来,因为我的第二个过滤器列表很长。
我正在努力处理两种不同类型的元素并将选择的值组合到一个选项数组中。我可以使过滤器彼此独立工作(下面的代码),但它们需要一起工作。如何将两个不同的操作(单击或更改)和两个属性(class= 或 value=)组合到一个选项数组中以传递给同位素过滤器?
var $container = $('#library');
// select ccskills publications by default
$container.isotope({ filter: '.ccskills' });
var $optionSets = $('#library-options .option-set'),
$optionLinks = $optionSets.find('a');
$optionLinks.click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return false;
}
var $optionSet = $this.parents('.option-set');
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
// make option object dynamically, i.e. { filter: '.my-filter-class' }
var options = {},
key = $optionSet.attr('data-option-key'),
value = $this.attr('data-option-value');
// parse 'false' as false boolean
value = value === 'false' ? false : value;
options[ key ] = value;
$container.isotope( options );
return false;
});
// using the 'chozen' plugin to style my select element
$(".chzn-select").chosen().change(
function() {
var industry = $("option:selected", this).val();
$container.isotope({filter: industry});
}
);
【问题讨论】:
-
你不可能这样做,因为用户不能同时做出这两个动作。否则使用全局变量来收集数据并使用数组 merge[r] 或类似的东西
-
谢谢瓦尔。我想将过滤器组合为两个单独的操作 - 我只需要确保这种过滤器组合一起执行。否则我会得到我目前拥有的东西,这是覆盖前一个动作的最后一个动作!我会看看你建议的合并。
-
我想我已经弄清楚了(有点不雅!) - 我正在检查每个功能的“其他”列表并将过滤器附加到我正在更新的那个。像这样: ` $("#industry-dropdown").chosen().change( function() { var Industry = $("option:selected", this).val(); var publisher = $optionSets.find( 'a.selected').attr('data-option-value'); $container.isotope({filter: Industry+publisher}); } );`
-
抱歉,我的评论似乎无法很好地格式化
-
使用打勾按钮通常在键盘上的选项卡按钮顶部,类似于单引号
标签: jquery select click jquery-isotope