Google places autocomplete, how to clean up pac-container?

后端 未结 5 1956
鱼传尺愫
鱼传尺愫 2021-02-12 13:41

I\'m using the google places autocomplete control, and it creates an element for the drop down with a class pac-container.

I\'m using the autocomplete in a

5条回答
  •  清酒与你
    2021-02-12 13:57

    My implementation of code from above without jquery.

    var autocomplete = new google.maps.places.Autocomplete(element, options);
    

    export function getAutocompletePacContainer(autocomplete) {
     const place: Object = autocomplete.gm_accessors_.place;
    
     const placeKey = Object.keys(place).find((value) => (
        (typeof(place[value]) === 'object') && (place[value].hasOwnProperty('gm_accessors_'))
     ));
    
     const input = place[placeKey].gm_accessors_.input[placeKey];
    
     const inputKey = Object.keys(input).find((value) => (
       (input[value].classList && input[value].classList.contains('pac-container'))
     ));
    
     return input[inputKey];
    }
    

    getAutocompletePacContainer(autocomplete).remove()
    

提交回复
热议问题