Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

237
Vistas
javacsript error Cannot read properties of undefined (reading 'createItemMarkup') in .forEach

I have a very simple class,

class LocationSearch extends BaseComponent {

    constructor(element) {
        super(element);
        
        this.initializeSearch();
    }

    initializeSearch() {
        this.service = new window.google.maps.places.AutocompleteService();
        this.service.getPlacePredictions({
            input: 'The Black Bull'
        }, this.displayResults);
   }

   displayResults(predictions, status) {
       if(status !== window.google.maps.places.PlacesServiceStatus.OK) {
            this.searchResults = [];
            return false;
        }

        const results = predictions.map((prediction) => prediction.structured_formatting);
        const resultsWrapper = SelectorEngine.findOne('.location-search-results-list');
        results.forEach((result) => {
            const item = this.createItemMarkup(result);
            resultsWrapper.append(item);
        });
    }
    

    createItemMarkup(item) {
        const { main_text, secondary_text} = item;
        const listElement = document.createElement('li');
        const buttonElement = document.createElement('button');
        const firstLine = document.createTextNode(main_text);
        const lineBreak = document.createElement('br');
        const secondLine = document.createTextNode(secondary_text);

        buttonElement.setAttribute('class', 'location-search-results-list__item');
        buttonElement.setAttribute('type', 'button');
        buttonElement.setAttribute('role', 'option');

        buttonElement.append(firstLine)
            .append(lineBreak)
            .append(secondLine);
        
        listElement.append(buttonElement);

        return listElement;

    }
}

When entering the forEach portion of the displayResults method I get the following error,

Cannot read properties of undefined (reading 'createItemMarkup')

I cant figure out what is going on to make it undefined?

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda