Implement Javascript Function Callback with GWT JsInterop

后端 未结 1 1407
难免孤独
难免孤独 2021-01-22 06:10

I want to wrap a javascript code like this :

map.addMarker({
        lat: -12.043333,
        lng: -77.028333,
        draggable: true,
        fences: [polygon         


        
1条回答
  •  囚心锁ツ
    2021-01-22 06:56

    I finally found a solution. It appears that my java code was inconsistent with my javascript code. Thanks to Colin Alworth for pointing me the inconsistent part. So here is my full code :

    @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;
    }
    

    Now whenever I run it, the outside function callback was invocated correctly. Thanks everyone. I hope my answer could help many others developer who tried to figured out how to implement js callback function with GWT JSInterop.

    0 讨论(0)
提交回复
热议问题