2017-06-12 48 views
1

下面是具有根據我的業務需要更改行,列的邏輯的代碼。當我把這個代碼,在我的Angular2 TS的代碼,我正在提供的參數根本不.forEach(符合調用對象的任何錯誤簽名......Angular2:ts - 提供的參數與調用目標的任何簽名不匹配

var data = [{ Id: "a", ColumnLocation: "0", RowLocation: "0" }, { Id: "b", ColumnLocation: "0", RowLocation: "1" }, { Id: "4", ColumnLocation: "0", RowLocation: "3" }, { Id: "c", ColumnLocation: "1", RowLocation: "0" }, { Id: "d", ColumnLocation: "1", RowLocation: "2" }, { Id: "e", ColumnLocation: "2", RowLocation: "0" }, { Id: "e", ColumnLocation: "2", RowLocation: "2" }]; 

data.forEach(function (col, row) { 
       return function (o) { 
        if (col !== o.ColumnLocation) { 
         col = o.ColumnLocation; 
         row = 0; 
        } 
        if (+o.RowLocation !== row) { 
         o.RowLocation = row.toString(); 
        } 
        row++; 
       } 
      }()); 
+2

哪裏是'data'?你有沒有我一個做'array.forEach'? –

+0

什麼是數據?你使用'array'編輯:Bah。弗蘭克打我:) – mc01

+0

它不是數組,它是數據。道歉.. – indra257

回答

1

至於爲了使用自執行的函數中提到他人與參數,你需要提供這些參數。

let myCol; // or you can set this to an initial value 
let myRow; 

data.forEach(function (col, row) { 
      return function (o) { 
       // your logic here 
      }; 
     }(myCol, myRow)); 

您的打字稿編譯器是抱怨,因爲你的函數有兩個參數colrow但你不帶任何參數調用它。

+0

這裏x和y是什麼? – indra257

+0

我打算寫這個,除了代碼編譯。但是你需要將'myCol'和'myRow'在底部傳遞以正確運行。 –

+0

@FrankModica但是x和y在這裏代表什麼 – indra257

相關問題