I'm relatively new to Backbone and I'm trying to use a PageableCollection in my application.
https://github.com/wyuenho/backbone-pageable
Could someone please point me, what am I doing wrong? I'm using backbone 1.0.0
I have a collection and a model defined like this:
var VoteList = Backbone.PageableCollection.extend({
model: Vote,
url: config.service + 'votes'
});
var Vote = Backbone.Model.extend({
url: function () {
return config.service + 'vote/' + this.id;
}
});
Later in the application:
this.collections.voteList = new VoteList([], {mode: "client", state: {pageSize: 12}});
....
this.collections.voteList.remove(options.model);
PageableCollection.remove() method fires a DELETE event which uses the URL of VoteList collection(?) to access a web service which in turn produces me an error 405 "Method not allowed" as a DELETE method is supposed to have an {id}
@DELETE
@Path("/vote/{id}")
@Consumes({MediaType.APPLICATION_JSON})
public void deleteVoting(@PathParam("id") Integer id) {
log.info("deleting " + id.toString());
}
When I remove pagination just by instantiating normal Backbone.Collection
var VoteList = Backbone.Collection.extend({ ... });
everything works as expected, Backbone uses a model url + id when deleting. So my question is how to make the PageableCollection to behave just in the same way?
This morning got a mail from the plugin author, it appears to be a known bug in Backbone 1.0.0. I guess it will gone away with version 1.0.1
Please see this thread: https://github.com/wyuenho/backbone-pageable/issues/70
To solve problem now I used a latest 'master' branch of Backbone which has this issue fixed:
https://raw.github.com/jashkenas/backbone/master/backbone.js
Alternatively, if you can't for some reason use a development branch, a temporary solution like this will also work:
var Vote = Backbone.Model.extend({
initialize: function () {
this.url = function () {
return config.service + 'vote/' + this.get('id')
}
}
});
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