【问题标题】:Angular2: ts - Supplied parameters do not match any signature of call targetAngular2:ts - 提供的参数与调用目标的任何签名都不匹配
【发布时间】:2017-11-14 02:33:51
【问题描述】:

下面是具有根据我的业务需要更改行、列的逻辑的代码。当我保留此代码时,在我的 Angular2 ts 代码中,我得到 Supplied parameters do not match any signature of call target error at .forEach(...

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++;
                }
            }());

【问题讨论】:

  • data 在哪里?你的意思是array.forEach
  • data 是什么?你使用array 编辑:呸。弗兰克打败了我 :)
  • 不是数组,是数据。道歉..
  • 好的,所以现在你传递给forEach 的函数实际上会传入不同的东西(数组中的元素、索引和数组)。查看developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…。您能否更新您的问题以考虑到这一点?
  • 是的。我已经更新了问题。

标签: javascript angular typescript


【解决方案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));

您的 typescript 编译器正在抱怨,因为您的函数采用两个参数 colrow,但您在没有任何参数的情况下调用它。

【讨论】:

  • 这里的 x 和 y 是什么?
  • 我也打算写这个,除了代码可以编译。但是您需要在底部传递 myColmyRow 以使其正常运行是正确的。
  • @FrankModica 但是 x 和 y 在这里代表什么
  • @indra257 x 和 y 是您想要的 col 和 row 的占位符。它们可以是数字或对其他一些参数的引用。如果你想在没有任何值的情况下开始,你可以只写 let myCol, myRow。
猜你喜欢
  • 2017-08-24
  • 2017-05-08
  • 2016-12-07
  • 2018-01-08
  • 2016-11-27
  • 2016-06-09
  • 2017-11-18
  • 2023-03-15
  • 2017-04-28
相关资源
最近更新 更多