javascript - 结合两个过滤器功能
问题描述
我想结合使用两个过滤器函数来选择表格中的一些元素。我的代码如下所示:
a = $('table td').filter(function(index) {
return index >= number1
});
b = $('table td').filter(function(index) {
return index < number2
});
merge = $.merge(a, b);
from 的元素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) )
推荐阅读
- typescript - 将类型保护中的“字符串”缩小为“keyof T”(hasOwnProperty)
- php - PHP 将作为 ASCII 的字符串变量转换为 UTF8_unicode_ci 保留国家字符
- go - 响应 MY_CONTACTS_OVERFLOW_COUNT 限制速率
- asp.net - 通信对象 System.ServiceModel.ChannelFactory`处于故障状态
- javascript - 退出 Laravel 后无法登录
- node.js - nvs 使用命令在 Windows 中的 git bash 命令提示符中不起作用
- java - 安卓|| 在 Hilt 不支持的类中注入依赖项,例如 Helper 类
- python - Pandas 数据框将行值重塑为新列(矩阵类型格式)
- vim - Vim Ctrlp 插件在 Windows 中搜索另一个驱动器中的文件
- php - 无法连接到 SMTP 主机 - 无法验证证书