数组角度重复的对象

时间:2018-03-25 08:23:45

标签: angular

在将对象添加到数组之前,我遇到了重复检查的问题。由于某种原因,检查总是返回-1,因此会添加重复的对象。这有什么问题?

  export interface StressTestAnalysis extends GraphConfiguration {

    curlevel: number;
    decrease: number;
    increase: number;
    yaxis: number[];
    data: number[];
    seriesName: string;
    color: string;
}


 public results: Array<StressTestAnalysis> = [];

@Input() set stressResults(value: Array<StressTestAnalysis>) {
    this._stressResults = value;
    this.addSeries();
    let minY = Math.min(...this.yAxisSeries.map(el => Math.min(...el.yaxis)));
    let maxY = Math.max(...this.yAxisSeries.map(el => Math.max(...el.yaxis)));
    this.generateYAxisArray(minY, maxY);

  }


this.results =  this._stressResults.map((result: any) => {

      var index = this.results.findIndex(item => item.seriesName === result.data.seriesName);

      if (index > -1) {
      result.chartSeries =  this.chartSeries.push({ data: result.data, name: result.seriesName, color: result.color });
      result.yAxisSeries = this.yAxisSeries.push({ yaxis: result.yaxis });
      }
      return result;
    });

0 个答案:

没有答案