codeforbtv / live-music-venue-directory

Live Music Venue Directory
4 stars 6 forks source link

Figure out how endpoint URLs should be configured in client scripts #26

Closed benglass closed 11 years ago

benglass commented 11 years ago

Currently the search_venues.php endpoint is in the config.js and I'm not sure thats the right place.

Possibly Backbone already has some best-practice for this. Perhaps it should be attached to the VenueCollection so that you can do something like load the collection automatically from the endpoint using the search criteria?

benglass commented 11 years ago

Looks like Backbone.Collection has a method called fetch[1] which accepts an options hash with data as one of the keys. The criteria model.toJSON can be used as the data key and by setting the url on the VenueCollection to '/search_venues.php' we can load venues by criteria using syntax like...

venueCollection.fetch({
    data: {
        location: 'Burlington, VT'
    }
});

Since VenueSearch is a Model we can also just pass that directly to data via venueSearch.toJSON()

[1] http://backbonejs.org/#Collection-fetch