数组中的模糊查询
const keys = _this.column.map((item) => item.code);
this.list = list.filter((item) => {
let res = keys.some((key) => {
if (item[key] !== null) {
return String(item[key]).includes(e);
}
});
return res;
});
当出现item[key].includes is not a function时
检查以下几点
- 是否存在null的参数
所以加上null的判断
if (item[key] !== null) {
return String(item[key]).includes(e);
}
- 字段是否是字符串类型的
转一下类型再使用includes
String(item[key]).includes(e);