Backbone.js: urlRoot with http query string?
11,141
Solution 1
You will have to use a custom url function for the model.
Book.url = function() {
return this.urlRoot + '/' + this.id + '?details=true';
};
Solution 2
You can also use the option for the method fetch
mybook.fetch({data:{details: true}});
Comments
-
Lai Yu-Hsuan almost 2 years
In
Backbone.js
I can appoint where the model fetches it's data:var Book = Backbone.Model.extend({urlRoot : '/books'}); var mybook = new Book({id: "1"}); mybook.fetch(); //it will access '/books/1'
But if I want to append a query string after the URL? e.g. the book data is at
/books/1&details=true
. Can I specify this in model? -
Tom over 10 yearsAlthough the accepted comment works, this seems to be the 'backbone way'
-
talltolerablehuman over 8 yearsI wish there was a way to define it on a model/collection level. this way you have to pass the
data
each time you call the fetch, would be nice if you could just set thedata
once on the model itself.