我正在尝试创建一个过滤器插件, 在init和其他函数之后我得到了两个数组
foo1=[test,test2,test3]
foo2=[test,test3]
现在我必须显示数据属性tin foo2的元素,它们等于foo1中的clicked元素数据属性
这是我的代码:
r$.each($FILTER.foo2elem, function() {
var elemfoo2 = $(this).data();
var elemfoo2data = $(this).data().foo2elem.split(' ');
r$.each($FILTER.foo1saved, function(i, selectedFilters) {
if ($.inArray(selectedFilters, elemfoo2data) !== -1) {
console.log(selectedFilters + ' è uguale a ' + elemfoo2data);
console.log('show element with foo2 data equal to foo1');
//how can i hook that element
} else {
console.log('hide');
//how hide other element
}
})
});
请帮助我,对不起我的英语
答案 0 :(得分:0)
尝试过滤器功能,然后返回项目,如果该对象在另一个数组中找到。我喜欢使用它,因为这个可以与任何对象进行比较。祝你好运。
$(function() {
var foo1 = ['one', 'two', 'three'];
var bar1 = ['one', 'three'];
var rr = foo1.filter(function(index) {
return jQuery.inArray(index, bar1) != -1;
});
console.log(rr);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>