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