角度无序句子搜索



在我的代码中,我有一个搜索栏,我试图根据我所写的内容过滤列表中的元素。如果我按顺序搜索元素,过滤器工作正常。例如,如果我像搜索'red blue'一样搜索'red blue yellow',但是,当我也将其搜索为'red yellow'时,我希望过滤器工作。这是我的代码,我应该添加什么来实现我想要的?

HTML:

<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Filter">

TS:

dataSource: MatTableDataSource<IProduct>;
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ViewChild(MatSort, { static: true }) sort: MatSort;
filterPredicate(data: IProduct, filter: string) {
let fullText = "";
fullText += data.StockIntegrationCode;
fullText += data.ProductGroup ? data.ProductGroup.GroupName : "";
fullText += data.ProductCategory
? data.ProductCategory.CategoryName
: "";
fullText += data.ProductName;
fullText += data.Description;
fullText += data.UnitType ? data.UnitType.Name : "";
fullText += data.IsActive ? "Aktif" : "Taslak";
return (fullText as any).toLocaleLowerCase("tr").indexOf(filter) >= 0;
}
applyFilter(filterValue: string) {
if (this.dataSource) {
this.dataSource.filter = filterValue.trim().toLocaleLowerCase();
if (this.dataSource.paginator) {
this.dataSource.paginator.firstPage();
}
}
}

想象一下你可以使用

fullText=fullText.loLocaleLowerCase("tr")
return filter.split(' ').filter(x=>(fullText.indexOf(x)<0)).length==0

那,把你的";滤波器";,然后你有,例如["red","yellow"],并只过滤数组中不在fullText中的元素。

如果没有(长度==0(是因为所有内容都在全文中。

注意:我编写fullText=fullText.loLocalLowerCase("tr"(以不重复每个"tr";单词";过滤器中。

最新更新