首先,是的,我已经搜索并找到了这个答案:
GWT JSNI - problem passing Strings
我正在尝试从 JSNI 方法调用 java 方法,但没有任何进展。我已经尝试了上面给出的建议,但仍然行不通。
代码如下:
public native void initCustomListeners(MapmakerMapViewPresenter.MyView view) /*-{
//public native void initCustomListeners() /*-{
$wnd.getLocationDescriptions = function(lng, lat) {
$entry(view.@org.jason.mapmaker.client.view.MapmakerMapViewImpl::getLocationDescriptions(DD)(lng, lat));
}
$wnd.google.maps.event.addListener(map, 'click', function(event) {
var lat = event.latLng.lat().toFixed(3);
var lng = event.latLng.lng().toFixed(3);
alert("(" + lat + ", " + lng + ")");
$wnd.getLocationDescriptions(lng, lat);
alert("Test!");
});
}-*/; @Override
public void getLocationDescriptions(double lng, double lat) {
getUiHandlers().doGetLocationDescriptions(lng, lat);
}
谁能帮帮我?
杰森
最佳答案
我不知道这是否是问题所在(您甚至没有说明该代码的行为方式与您期望的行为方式),但您的代码中存在一些错误:
$entry
包装了一个函数,所以你必须调用它返回的函数,而不是(无用地)包装函数调用后的结果! IE。$entry(function(lat,lng) { foo.@bar.Baz::quux(DD)(a, b); }
而不是$entry(foo.@bar.Baz::quux(DD)(a, b))
您在
map
上addListener
,但从未定义该变量。
关于java - 从 GWT JSNI 调用 Java 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7325740/