【问题标题】:Closure call with mismatched arguments: function 'call' again参数不匹配的闭包调用:再次调用函数
【发布时间】:2013-12-18 16:57:11
【问题描述】:

就在一个月前,我遇到了这个问题Closure call with mismatched arguments: function 'call' 与 js 互操作。

现在我对SnapSVG 库也有同样的问题。从那一刻起,我就将它与 JsInterop 结合使用。今天我尝试使用mouseover 函数,我得到了同样的异常。

但是当我将鼠标悬停在 SVG 元素上时,我的函数会被触发四次:

hover in
hover in
hover in
hover in 
Breaking on exception: Closure call with mismatched arguments: function 'call'

我试过了:

var img = s.image("$url", x, y, image.width/2, image.height/2); 
js.FunctionProxy hover = new js.FunctionProxy(() {
  print("hover in");
});

img.mouseover(hover);

var img = s.image("$url", x, y, image.width/2, image.height/2);
img.mouseover(() {
  print("hover in");
});

这次检查了两次,回调函数没有多余的参数。

【问题讨论】:

    标签: callback dart dart-js-interop


    【解决方案1】:

    考虑到您粘贴的日志,mouseover 处理程序似乎有时会使用参数调用,有时却没有。要处理这个问题,您可以使用带有可选参数的函数:

    var img = s.image("$url", x, y, image.width/2, image.height/2);
    img.mouseover(([p1, p2, p3, p4]) {
      print("hover in");
    });
    

    上面的回调现在处理带有 0 到 4 个参数的调用。

    【讨论】:

    • 该死的......它成功了......这很奇怪......谢谢你,Alexandre!
    猜你喜欢
    • 2013-12-01
    • 2022-12-21
    • 1970-01-01
    • 2022-08-13
    • 2021-12-09
    • 2021-12-10
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多