【问题标题】:Angular 5 -> Filter "like %" (we SQL)Angular 5 -> 过滤“like %”(我们 SQL)
【发布时间】:2018-03-17 20:01:05
【问题描述】:

我有一个数组的过滤器。

 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 中创建一个 Like 'var%' 我们吗?

【问题讨论】:

    标签: sql angular typescript filter


    【解决方案1】:

    不,你不能。 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)
    • @StoRm Tec:我明白了,但是 indexOf() 会为您执行此操作。它的工作原理如下: 1. 找到字符串,例如“从 Nagel 中选择 *,其中 Bezeichnung1 喜欢 %W101%”。 2. 找到字符串?然后返回它的起始索引。 -- 所以你得到一个大于-1的索引。您可以确定您在 Nagel 中的 Bezeichnung 包含您正在搜索的字符串。如果未找到该字符串,您将得到 -1 并且 filter() 将忽略此条目。 -- 你试过了吗?
    • 很高兴来到这里。别提了。 ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-19
    • 2018-08-21
    • 1970-01-01
    • 2021-08-08
    相关资源
    最近更新 更多