改變數組對象的屬性名稱,不改變屬性值


  console.log(this.oneAgData['Detail']);
    this.DetailFirstColumn = [];
    this.DetailSecondColumn = [];
    // this.DetailThirdlyColumn = [];

    for (var j = 0; j < this.oneAgData['Detail'].length; j++) {   //--循環所有的列
      if (j % 3 == 0) {
        this.DetailFirstColumn.push(this.oneAgData['Detail'][j]);
      } else if (j % 3 == 1) {
        let obj = {};
        for (let k in this.oneAgData['Detail'][j]) {
          obj[k + '1'] = this.oneAgData['Detail'][j][k];
        }
        this.DetailFirstColumn.push(obj);
      } else if (j % 3 == 2) {
        let obj = {};
        for (let k in this.oneAgData['Detail'][j]) {
          obj[k + '2'] = this.oneAgData['Detail'][j][k];
        }
        this.DetailFirstColumn.push(obj);
      }
    }

    console.log(this.DetailFirstColumn);

    for (let i = 0; i < this.DetailFirstColumn.length; i++) {
      if (i % 3 == 0) {
        this.DetailSecondColumn.push(this.DetailFirstColumn[i]);
      } else if (i % 3 == 1) {
        Object.assign(this.DetailSecondColumn[this.DetailSecondColumn.length - 1], this.DetailFirstColumn[i]);
      } else if (i % 3 == 2) {
        Object.assign(this.DetailSecondColumn[this.DetailSecondColumn.length - 1], this.DetailFirstColumn[i]);
      }
    }
    console.log(this.DetailSecondColumn);

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM