jquery - 如何显示数据属性等于数组值的元素

jquery - how to show elements with data attribute equal to value of array

我正在尝试创建一个过滤器插件, 在初始化和其他函数之后我得到了两个数组

foo1=[test,test2,test3]
foo2=[test,test3]

现在我必须显示数据属性为 tin foo2 的元素,这些元素等于 foo1 中单击的元素数据属性

这是我的代码:

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
    }
})

});

请帮助我,我很抱歉我的英语不好

尝试过滤功能,如果在另一个数组中找到该对象,则尝试 return 项。我喜欢使用它,因为它可以与任何对象进行比较。祝你好运。

$(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>