利用new Map()做多选

  public setChooseitem = new Map();
  public chooseIndex: number[] = []; //当前选择的index  css做选中颜色处理

  get length() {
    return this.chooseIndex.length;
  }
  
    /**@function handelBill 操作选中的发票   
    //@params item 当前选中的发票
    //@params index 当前选择的发票index
  handelBill(item: any, index: number) {
    if (this.setChooseitem.has(index)) {
        //判断 是否已经选中该index
      this.setChooseitem.delete(index);
        //若选中就删了
      const cIndex = this.chooseIndex.findIndex((i) => i == index);
      this.chooseIndex.splice(cIndex, 1);

    } else {
     //没选过就直接加进去
      this.setChooseitem.set(index, item);
      this.chooseIndex.push(index);
    }
  }

new Map 操作

has判断是否有该key

delete删掉该key

set 设置一个key

用new map的优点就是,快速找到该key

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值