0

我是 GWT 和 Javascript 的新手。

我正在尝试将 java int[] 发送到我的 javascript 函数。我正在使用 gwt-exporter 为我处理处理。这就是我设置的方式。

static class gwtExplorerTest implements Exportable {

    @Export("$wnd.handleAnchorClick")
    public static void handleAnchorClick(int param1, int param2 , int[] a1 , int[] a2)
    {
        //process  things here          
    }
}

有人可以帮我用javascript代码传入我需要的数组吗?我目前拥有的是:

href="javascript:window.handleAnchorClick(" + currentRow + "," + currentColumn + "," + rowVals + "," + colVals + ",") "

作为我的 JS 函数调用,其中 rowVals 和 colVals 是我需要传入的两个数组。它似乎不起作用。有人可以帮我吗?

谢谢

4

2 回答 2

0

如果您使用的是 json 字符串,那么我希望您需要在 handleAnchorClick 方法中将参数类型更改为字符串。然后你需要类型转换为 json。

于 2013-04-19T07:20:23.690 回答
0

您在 java 中的函数是正确的,并且 gwt-exporter 支持这种语法。来自 JS 的调用应该是这样的:

 window.handleAnchorClick(1, 2, [3,4], [5,6])

您的问题是您试图从您的href属性中调用导出的方法,html并且您使用了错误的语法。

首先,最好使用onClick属性而不是href,因为你不需要javascript:标签,最好防止默认。而且,我宁愿定义一个函数来进行调用以避免语法问题。

<script>
  var currentRow = 1;
  var currentColumn = 2;
  var rowVals = [3,4];
  var colVals = [5,6];

  function mycall() {
    window.handleAnchorClick(currentRow, currentColumn, rowVals, colVals);
  }
</script>

<!-- I prefer this -->
<a href="#" onClick="javascript:mycall()">click</a>

<!-- But this should work as well -->
<a href="#" onClick="window.handleAnchorClick(currentRow,currentColumn,rowVals,colVals)">click</a>
于 2013-04-19T07:03:57.720 回答