使用GWT JsInterop实现Javascript函数回调

我想包装像这样的javascript代码:

map.addMarker({ lat: -12.043333, lng: -77.028333, draggable: true, fences: [polygon], outside: function(m, f){ alert('This marker has been moved outside of its fence'); } }); 

我在这里用Java编写它:

 @JsType(namespace = JsPackage.GLOBAL, isNative = true, name = "Object") public class MarkerOptions { @JsProperty public double lat; @JsProperty public double lng; @JsProperty public boolean draggable; @JsProperty public Polygon fences; @JsFunction public interface FunctionOutsideParam { void outside(); } @JsProperty public FunctionOutsideParam outside; } 

但它不起作用。 即使你在我的浏览器控制台中没有任何错误。 有人知道如何让它为外部回调函数工作吗? 感谢致敬。

我终于找到了解决方案。 看来我的java代码与我的javascript代码不一致。 感谢Colin Alworth指出我不一致的部分。 所以这是我的完整代码:

 @JsType(namespace = JsPackage.GLOBAL, isNative = true, name = "Object") public class MarkerOptions { @JsProperty public double lat; @JsProperty public double lng; @JsProperty public boolean draggable; @JsProperty public Polygon[] fences; @JsFunction public interface FunctionOutsideParam { void outside(Marker m, Polygon[] f); } @JsProperty public FunctionOutsideParam outside; } 

现在每当我运行它时,外部函数回调被正确调用。 感谢大家。 我希望我的回答可以帮助许多其他开发人员试图找出如何使用GWT JSInterop实现js回调函数。