繁体   English   中英

结合两个过滤器功能

[英]combining two filter functions

我想将我正在使用的两个过滤器函数组合到 select 表格中的几个元素。 我的代码如下所示:

a = $('table td').filter(function(index) {
    return index >= number1
}); 
                        
b = $('table td').filter(function(index) {
    return index < number2
});
                        
merge = $.merge(a, b);

a中的元素必须是第一个并且在一行中。 因此,如果a返回 3 个元素,它们必须在一行中,然后是b中的元素。 我怎样才能做到这一点? 我可以结合上面的过滤器功能吗?

您最好使用.slice方法而不是过滤器,例如:

list = $('table td')
merge = [...list.slice(number1), ... list.slice(0, number2)]

或者如果你真的想使用过滤器,那么:

list = $('table td')
merge = list.filter((item, i) => (i >= number1 || i < number2)  )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM