我是GWT和Javascript的新手。
我正在尝试向我的javascript函数发送一个java int[]。我正在使用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是我需要传入的两个数组。它似乎不起作用。有谁能帮帮我吗?
谢谢
发布于 2013-04-19 15:03:58
您在java中的函数是正确的,gwt-exporter支持此语法。来自JS的调用应该如下所示:
window.handleAnchorClick(1, 2, [3,4], [5,6])您的问题是,您正在尝试从html中的href属性调用导出的方法,并且使用了错误的语法。
首先,最好使用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-19 15:20:24
如果您使用的是json string,那么我希望您需要在handleAnchorClick方法中将参数类型更改为string。然后,您需要将类型转换为json。
https://stackoverflow.com/questions/16098288
复制相似问题