I've got a rest service running with mers (https://github.com/jspears/mers).
Now I'd like to connect it to backbone.js
The problem is that mers returns the collection wrapped in a payload array with additonal info:
e.g.
{"payload":[
{"_id":"4fe3773ffca7f74410000001","pos":[48.123447013691425,11.57250838808296],"username":"AyKarsi","pictures":[],"images":[],"roles":[],"meta":{},"groups":[]},
{"_id":"4fe3773ffca7f74410000002","pos":[0,3444],"username":"TestUpdateFromClient","pictures":[],"images":[],"roles":[],"meta":{},"groups":[]},],
"status":0,"total":5}
This info is nice to have, but how can I tell the backbone collection where it should look for the models?
You'll want to override the default parse
function in Backbone.Collection
.
var MyCollection = Backbone.Collection.extend({
parse: function(models) {
return models.payload;
}
}
Here's the relevant documentation on the Backbone.js website.