Angular2 字典的实现

使用Map

  • 创建Map类型的字典,增加元素
  this.dicMap = new Map<string,number>();
                dicMap.set("zhangsan",20);
                dicMap.set("lisi",30);
                dicMap.set("wangwu",40);                        
  • 获取字典的value
    private getMapValue(key:string){
        if( key != null ){
            return this.dicMap.get(key);
        }    
    }
  • 绑定到html
 <td class="overflow-td">总量</td>
 <td class="overflow-td" *ngFor = "let c of items">{{getMapValue(c)}}</td>
发布了69 篇原创文章 · 获赞 0 · 访问量 985

猜你喜欢

转载自blog.csdn.net/qq_21209307/article/details/105247991