Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js: urlRoot with http query string?

Tags:

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?

like image 486
Lai Yu-Hsuan Avatar asked Mar 27 '12 06:03

Lai Yu-Hsuan


2 Answers

You can also use the option for the method fetch

mybook.fetch({data:{details: true}}); 
like image 198
Shuping Avatar answered Oct 12 '22 23:10

Shuping


You will have to use a custom url function for the model.

Book.url = function() {   return this.urlRoot + '/' + this.id + '?details=true'; }; 
like image 42
abraham Avatar answered Oct 12 '22 23:10

abraham