13

I'm trying to keep an array of object literals in sync with server data. These objects are being placed on a Google map via backbone.googlemaps extension.

I have a collection:

var LocationList = Backbone.Collection.extend({ model: Location, url: '/locations' })

How can I grab an array of object literals from this LocationList collection? My goal is such:

[{name: "Home", address: "123 Pleasant St"}, {name: "Work", address: "123 Unpleasant St"}]

professormeowingtons
  • 3,504
  • 7
  • 36
  • 50

2 Answers2

25

You are looking for the .toJSON() method of the collection, see here:

var locations = new LocationList();

locations.toJSON();
Cubed Eye
  • 5,581
  • 4
  • 48
  • 64
3

use underscore.js pluck method: http://underscorejs.org/#pluck

Eru
  • 675
  • 4
  • 8