如何在搜索时排除空格



在 Angular2+ 中,我写了一个用于搜索数组的管道,它工作正常。 但我想排除数组中的空格。

我目前的管道

import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'arraySearch'
})
export class ArraySearchPipe implements PipeTransform {
transform(value: any, args?: any): any {
if (!args) { return value; }
return value.filter(item => this.checkValues(item, args));
}
checkValues(item, args) {
const value = Object.keys(item).map(k => item[k]);
return String(value).indexOf(args) > -1;
}
}

这段代码搜索具有确切术语的术语。如何排除数组项目中的空格并进行搜索?

谢谢。

尝试以下操作:

checkValues(item, args) {
const value = Object.keys(item).map(k => item[k]);
return String(value).replace(/ /g,"").indexOf(args) > -1;
}

最新更新