Is not a constructor - seatgeeksearch tutorial

2842
3
10-02-2013 08:52 PM
thomasenns1
New Contributor
I'm upgrading my code to amd and educating myself with the Seatgeeksearch tutorial.  I've done this, now, on a couple different machines and I get an error - "Seatgeeksearch is not a constructor".   Any help or direction would be greatly appreciated.  I seems at though seatgeeksearch.js seems to load okay.
0 Kudos
3 Replies
derekswingley1
Frequent Contributor
Please post your code that shows the problem. The example using the code from that tutorial works without issue:  http://servicesbeta.esri.com/demos/using-classes-with-javascript/seatgeek-search/
0 Kudos
WillHughes1
Occasional Contributor II

define(

    ["dojo/_base/declare", "dojo/_base/lang", "esri/request"],

    function (declare, lang, esriRequest) {

        declare(null,

            {

                distance: null,

  lastSearchResult: null,

  perPage: null,

  queryParams: null,

  seatGeekUrl: null,

  constructor: function (options) {

    // specify class defaults

    this.distance = options.distance || "20mi"; // default seat geek range is 30mi

    this.perPage = options.perPageage || 50; // default to 50 results per page

    this.seatGeekUrl = "http://api.seatgeek.com/2/events";

   

    // returnEvents is called by an external function, esri.request

    // hitch() is used to provide the proper context so that returnEvents

    // will have access to the instance of this class

    this.returnEvents = lang.hitch(this, this.returnEvents);

  },

  searchByLoc: function (geopoint) {

    var eventsResponse;

    this.queryParams = {

      "lat": geopoint.y,

      "lon": geopoint.x,

      "page": 1,

      "per_page": this.perPage,

      "range": this.distance

    }

    // seat geek endpoints:

    // petco park search using lat, lon:

    // http://api.seatgeek.com/2/events?lat=32.7078&lon=-117.157&range=20mi&callback=c

    // lat, lon for petco park:  32.7078, -117.157

    eventsResponse = esriRequest({

      "url": this.seatGeekUrl,

      "callbackParamName": "callback",

      "content": this.queryParams

    });

    return eventsResponse.then(this.returnEvents, this.err);

  },

  getMore: function() {

    var eventsResponse;

    // increment the page number

    this.queryParams.page++;

   

    eventsResponse = esri.request({

      "url": this.seatGeekUrl,

      "callbackParamName": "callback",

      "content": this.queryParams

    });

    return eventsResponse.then(this.returnEvents, this.err);

  },

  returnEvents: function(response) { 

    // check number of results

    if ( response.meta.total == 0) {

      // console.log("Seat Geek returned zero events: ", response);

      return null;

    }

    // save search result

    this.lastSearchResult = response;

    // console.log("set last search result: ", response, this);

    return response;

  },

  err: function(err) {

    console.log("Failed to get results from Seat Geek due to an error: ", err);

  }

  });

    });

0 Kudos
WillHughes1
Occasional Contributor II

I was able to get this to work by adding "return" before declare on line 4.

define(

    ["dojo/_base/declare", "dojo/_base/lang", "esri/request"],

    function (declare, lang, esriRequest) {

      return declare(null,

Without return I was seeing the same "not a constructor" error mentioned in the original post.

It would be great if the Tutorial files were made available in the Samples or on GitHub. Thanks.

0 Kudos