1、include去重
仅限数组格式,对象格式不可以
if (!this.cTypeList.includes(element["cTypestation"])) {
this.cTypeList.push(element["cTypestation"]);
}
2、set去重 建立map表
public map = new Map<number, string>()
//初始化查询 表格数据
refresh() {
this.source = []; this.VegeStatisticsEleService.getNPPQuery().subscribe(data => {
//区域代码cCode 去重
let set = new Set<number>();
data.forEach(d => {
set.add(d.cCode);
})
//建立map表{ key:cCode value:cName}
set.forEach(item => {
this.promiseArr.push(this.AreaService.getByKey(item).then(nameData => {
this.map.set(item, nameData.cName)
}));
})
console.log(this.map);
});
}
//思路
li.isChecked=new Set(this.listOfId).has(li.id)
3.数组去重
e//年份
let item = {
label: this.selYear.toString(),
pngPrnStr: this.productService.makeProductName("BEHB", "VEGE", this.selYear + this.dateArr[1] + "00000000", this.selYear + this.dateArr[0] + "00000000", this.field, this.reso, "HL", "png"),
imgPrnStr: this.productService.makeProductName("BEHB", "VEGE", this.selYear + this.dateArr[1] + "00000000", this.selYear + this.dateArr[0] + "00000000", this.field, this.reso, "HL", "img")
}
this.array.forEach((d, i) => {
if (d.label == e) {
this.array.splice(i, 1, item)//有相同年份数据,更新该键值
}
})
if (!this.array.includes(item)) {
this.array.push(item);
}