简体   繁体   English

从js文件代码调用gwt函数。[错误不是函数]

[英]calling gwt function from js file code.[Error is not a function]

I am trying to call my GWT function from external js.But i am getting error ****window.myFunction** is not a function** 我正在尝试从外部js调用我的GWT函数,但出现错误**** window.myFunction **不是函数**

my js file is 我的js文件

 function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
    center : {
        lat : 34.149486,
        lng : -117.257317
    },
    zoom : 13
});
var geocoder = geocoder = new google.maps.Geocoder();

var card = document.getElementById('pac-card');
var input = document.getElementById('pac-input');
var types = document.getElementById('type-selector');
var strictBounds = document.getElementById('strict-bounds-selector');

map.controls[google.maps.ControlPosition.TOP_RIGHT].push(card);

var autocomplete = new google.maps.places.Autocomplete(input);

// Bind the map's bounds (viewport) property to the autocomplete object,
// so that the autocomplete requests use the current map bounds for the
// bounds option in the request.
autocomplete.bindTo('bounds', map);

var infowindow = new google.maps.InfoWindow();
var infowindowContent = document.getElementById('infowindow-content');
infowindow.setContent(infowindowContent);
var marker = new google.maps.Marker({
    position : {
        lat : 34.149486,
        lng : -117.257317
    },
    map : map,
    draggable : true,
    anchorPoint : new google.maps.Point(0, -29)
});

google.maps.event
        .addListener(
                marker,
                "dragend",
                function(e) {
                    var lat, lng, address;

                    geocoder
                            .geocode(
                                    {
                                        'latLng' : marker.getPosition()
                                    },
                                    function(results, status) {
                                        document
                                                .getElementById('pac-input').value = results[0].formatted_address;
                                        myfunction1()
                                    });
                });

autocomplete.addListener('place_changed', function() {
    infowindow.close();
    marker.setVisible(false);
    var place = autocomplete.getPlace();
    if (!place.geometry) {
        // User entered the name of a Place that was not suggested and
        // pressed the Enter key, or the Place Details request failed.
        window
                .alert("No details available for input: '" + place.name
                        + "'");
        return;
    }

    // If the place has a geometry, then present it on a map.
    if (place.geometry.viewport) {
        map.fitBounds(place.geometry.viewport);
    } else {
        map.setCenter(place.geometry.location);
        map.setZoom(17); // Why 17? Because it looks good.
    }
    marker.setPosition(place.geometry.location);
    marker.setVisible(true);

    var address = '';
    if (place.address_components) {
        address = [
                (place.address_components[0]
                        && place.address_components[0].short_name || ''),
                (place.address_components[1]
                        && place.address_components[1].short_name || ''),
                (place.address_components[2]
                        && place.address_components[2].short_name || '') ]
                .join(' ');
    }

    infowindowContent.children['place-icon'].src = place.icon;
    infowindowContent.children['place-name'].textContent = place.name;
    infowindowContent.children['place-address'].textContent = address;
    infowindow.open(map, marker);
});

// Sets a listener on a radio button to change the filter type on Places
// Autocomplete.
function setupClickListener(id, types) {
    var radioButton = document.getElementById(id);
    radioButton.addEventListener('click', function() {
        autocomplete.setTypes(types);
    });
}
    setupClickListener('changetype-address', [ 'address' ]);
  }
     function myfunction1() {
         window.myFunction();
     }

my java file is : 我的java文件是:

  package biz.kaar.service.client.shuttle;

  public class Trips extends MyPopup{

     Frame f = new Frame("js/location.html")

     public popupPanel(){
         super() ;
         exportMyFunction1() ;
         /* some other code line*/
      }
     //other methods.object of this class is created while loading

     public static native void exportMyFunction1() /*-{
      $wnd.myFunction =
             $entry(@biz.kaar.service.client.shuttle.Trips::myFunction());
     }-*/;

     public static void myFunction(){
         ErrorHandler.logInConsole("working");
        }

} }

my location.html file 我的location.html文件

 <!DOCTYPE html>
 <html>
 <head>
  <title>Place Autocomplete</title>
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
   <meta charset="utf-8">
  </head>
  <body>
   <div class="pac-card" id="pac-card">
  <div>
    <div id="title">
      Autocomplete search
    </div>
    <div id="type-selector" class="pac-controls">

      <input type="radio" name="type" id="changetype-address" value="mykaarma">
      <label for="changetype-address">Addresses</label>

      <input type="radio" name="type" id="changetype-geocode">
      <label for="changetype-geocode">Geocodes</label>
    </div>

  </div>
  <div id="pac-container">
    <input id="pac-input" type="text"
        placeholder="Enter a location" value = "St Marys Rd Sydney NSW 2000 Australia">
  </div>
</div>
<div id="map"></div>
<div id="infowindow-content">
  <img src="" width="16" height="16" id="place-icon">
  <span id="place-name"  class="title"></span><br>
  <span id="place-address"></span>
</div>

<script src = "location.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initMap"
    async defer></script>

Have i missed something in my code ? 我是否错过了代码中的某些内容?

Thanks. 谢谢。

您的JS代码位于iframe(“ Frame小部件)内部,并且您的函数已在父窗口中导出,因此它是window.parent.myFunction()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM