角度5->过滤器“like%”(我们SQL)

角度5->过滤器“like%”(我们SQL),sql,angular,typescript,filter,Sql,Angular,Typescript,Filter,我有一个数组的过滤器 filter(typ: string) { console.log("Filter"); this.nagelplattenFiltered == null; this.nagelplattenFiltered = this.nagelplatten.filter((nagel: Nagelplatten) => nagel.Bezeichnung1 === typ); this.nagelplatten = this.nagelplattenFiltered; c

我有一个数组的过滤器

 filter(typ: string) {
console.log("Filter");
this.nagelplattenFiltered == null;
this.nagelplattenFiltered = this.nagelplatten.filter((nagel: Nagelplatten) => nagel.Bezeichnung1 === typ);
this.nagelplatten = this.nagelplattenFiltered;
console.log(JSON.stringify(this.nagelplattenFiltered));
console.log("new: " + JSON.stringify(this.nagelplattenFiltered));
}


所以我们可以用SQL做一个类似“var%”的函数吗?

不,你不能。JavaScript中不存在此运算符。但是您可以使用indexOf方法,它以正确的方式使用,具有类似的效果

filter(typ: string) {
  console.log("Filter");
  this.nagelplattenFiltered == null;

  this.nagelplattenFiltered = this.nagelplatten.filter((nagel: Nagelplatten) => 
  nagel.Bezeichnung1.indexOf(typ) > -1);

  this.nagelplatten = this.nagelplattenFiltered;
  console.log(JSON.stringify(this.nagelplattenFiltered));
  console.log("new: " + JSON.stringify(this.nagelplattenFiltered));
}

您的筛选器现在提供所有包含类型字符串的Nagel对象。

谢谢您的回答。但我认为这都是一个类型字符串。在数组中,我有一个描述20W,W101,15N,所以我想过滤例如==W101或20W@StoRmTec:我明白了,但indexOf是为你做的。它的工作原理如下:1。查找字符串,例如从Nagel中选择*,其中Bezeichnung1类似于%W101%。2.找到字符串了吗?然后返回其起始索引。-所以你会得到一个大于-1的索引。您可以确保Nagel中的Bezeichnung包含您正在搜索的字符串。如果找不到字符串,您将得到-1,筛选器将忽略此项。-你已经试过了吗?很高兴来这里。别客气;