Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>According to your additionnal precisions stating that <strong>life</strong> is actually a book name...</p> <p>It looks like Backbone is better integrated with RESTful API's. In REST, your urls should not contain verbs and to search books, you would do a <code>GET /books/?name=life</code>. </p> <p>In that case, you would only have to define a <code>Backbone.Collection</code> like:</p> <pre><code>var BooksCollection = Backbone.Collection.extend({ model: Book, url: '/books' }); </code></pre> <p>The to fetch books:</p> <pre><code>var books = new BooksCollection(); books.fetch({data : {name: 'life'}}); //GET /books/?name=life </code></pre> <p>If you really want your search operation to target <code>/search/:name</code>, you will have to check the <a href="http://backbonejs.org/#Collection" rel="nofollow">Backbone.Collection</a> api, but I think you will want to look at <a href="http://backbonejs.org/#Sync" rel="nofollow">http://backbonejs.org/#Sync</a></p> <p>You could override your collection's <code>sync</code> method to something like:</p> <pre><code>Backbone.Collection.extend({ ... sync: function (method, model, options) { //for read operations, call the search url if (method === 'read') { options.url = '/search/' + options.data.name; delete options.data.name; } //call the default sync implementation return Backbone.Collection.prototype.sync.apply(this, arguments); } }); </code></pre> <p>In this cased calling <code>books.fetch({data : {name: 'life'}});</code> will result in <code>GET /books/life</code>.</p> <p>Here's a <a href="http://jsfiddle.net/KZuB7/1/" rel="nofollow">fiddle</a> that shows the example.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload