代码之家  ›  专栏  ›  技术社区  ›  Vithushan

如何在Angular 4+[复制]中更新贴图的现有键的值

  •  0
  • Vithushan  · 技术社区  · 8 年前

    是否有任何方法可以更新angular 4+中创建的键值对映射的值。

    假设我有:

    testMap: Map<number, string> = new Map<number, string>();
    
    ngOnInit() {
        this.testMap.set(1, "A");
        this.testMap.set(2, "B");
        this.testMap.set(3, "C");
        this.testMap.set(4, "D");
        this.testMap.set(5, "E");
    }
    
    changeValue(id){
        //id is the one of the keys of the map whose value needs to be altered
        //let say (id=3)
        this.testMap.put(id,"ChangedValue"); //PUT is from java
    }
    
    1 回复  |  直到 8 年前
        1
  •  9
  •   lupus137    8 年前

    您可以设置:

    this.testMap.set(id, "ChangedValue")
    
    推荐文章