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"}]
use underscore.js pluck method: http://underscorejs.org/#pluck
You are looking for the .toJSON()
method of the collection, see here:
var locations = new LocationList();
locations.toJSON();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With