2015-07-02 46 views
-1

我试图做google maps api example为SAP UI5和下面是我的XML视图:我怎样才能在SAP UI5 XML视图中获得html元素的值

<html:input id="pac_input" class="controls" type="text" 
     placeholder="Enter a location" /> 
    <html:div id="type_selector" class="controls"> 
     <html:input type="radio" name="type" id="changetype-all" checked="checked" /> 
     <html:label for="changetype_all">All</html:label> 

     <html:input type="radio" name="type" id="changetype_establishment" /> 
     <html:label for="changetype_establishment">Establishments</html:label> 

     <html:input type="radio" name="type" id="changetype_address" /> 
     <html:label for="changetype_address">Addresses</html:label> 

     <html:input type="radio" name="type" id="changetype_geocode" /> 
     <html:label for="changetype_geocode">Geocodes</html:label> 
    </html:div> 
    <html:div id="map-canvas" class="myMap"></html:div> 

我想“pac_input”输入在controller.js中通过Id“type_selector”div。但每当我尝试this.getView()。byId(“map_canvas”的),它说:this.getView不是一个函数 ,我想这是因为是Window对象,我不知道如何我可以获得元素。我会很乐意提供帮助。这里我controller.js:

onAfterRendering: function() { 
    if (!this.initialized) { 
     google.maps.event.addDomListener(window, 'load', function(){ 
      this.initialized = true; 
      util.Common.geocoder = new google.maps.Geocoder(); 
      util.Common.infowindow = new google.maps.InfoWindow(); 
      var mapOptions = { 
       center: new google.maps.LatLng(-34.397, 150.644), 
       zoom: 8, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
      }; 
      util.Common.googlemap = new google.maps.Map(this.getView().byId("map_canvas").getDomRef(), 
       mapOptions); 
      var input = this.getView().byId("pac_input"); 
      var types = this.getView().byId("type_selector"); 
      ... 

更新1:我想还可以通过sap.ui.getCore.byId()到达,但仍是不确定的。

回答

0

首先我在<html:div id="map-canvas" class="myMap"></html:div>.犯了一个错误ID应该是map_canvas提供。我将div元素嵌入到常见的变量中,并将其覆盖在onInit()上。现在它可以工作。

onInit : function() { 
    ... 
    util.Common.map_canvas_div = this.getView().byId("map_canvas"); 
    ... 
} 
onAfterRendering: function() { 
    var input = util.Common.pac_input_input; 
    ... 
}