Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

235
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!