如何在 sap ui5 xml 视图中获取 html 元素的值

How can I get value of html element in sap ui5 xml view

我正在尝试为 sap ui5 做 google maps api example,以下是我的 xml 观点:

    <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>

我想通过 controller.js 中的 Id 获取 "pac_input" 输入和 "type_selector" div。但是每当我尝试 this.getView().byId("map_canvas") 它说 this.getView is not a function 我想这是因为 this 是一个 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() 到达,但仍然未定义。

首先我在<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;
    ...
}