代码之家  ›  专栏  ›  技术社区  ›  Glory Raj

使用angular 4搜索数组中的元素

  •  1
  • Glory Raj  · 技术社区  · 7 年前

     let sourceList: SourceList[] = [
      {
        Value: "L7",
        Name: "L7",
        IsVisible: false
      },
      {
        Value: "LO",
        Name: "LO",
        IsVisible: false
      },
      {
        Value: "L3",
        Name: "L3",
        IsVisible: false
      },
      {
        Value: "LS",
        Name: "LS",
        IsVisible: false
      }
    ]
    

    到目前为止,代码已经尝试过了

     if(this.sourceList.indexOf("L7",0) != -1 && this.selectedSources.indexOf("LO",0) != -1 ){
    
      }
    

    但在“中出错” L7级 "

    我正在将此灵魂主义者数组中的项目逐个添加到另一个数组中,比如说array2。。 有没有办法检查souceList数组中的项是否在array2中。。

    我需要做一些过程,如果项目 “L7” 但我不知道如何在数组2中同时搜索这两个项。。

    谁能帮我一把,我会非常感激的

    1 回复  |  直到 7 年前
        1
  •  1
  •   ConnorsFan    7 年前

    some

    if (this.sourceList.some(x => x.Value === "L7") &&
        this.selectedSources.some(x => x.Value === "L0")) {
      ...
    }
    
    推荐文章