Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone.js Collections do not invoke "Reset" event after fetch operation
    text
    copied!<p>When requesting for <code>data.json</code> file for populating collection which has below data </p> <pre><code>[{ "Id": "BVwi1", "Name": "Bag It", "AverageRating": 4.6, "ReleaseYear": 2010, "Url": "http://www.netflix.com/Movie/Bag_It/70153545", "Rating": "NR" }, { "Id": "BW1Ss", "Name": "Lost Boy: The Next Chapter", "AverageRating": 4.6, "ReleaseYear": 2009, "Url": "http://www.netflix.com/Movie/Lost_Boy_The_Next_Chapter/70171826", "Rating": "NR" }] </code></pre> <p>Collection does not invoke the "Reset" event as the documentation says it should. I can view the request and response are correct after the fetch method but nothing happens. Below is the code for my app. Router that start's everything</p> <pre><code>Theater.Router = Backbone.Router.extend({ routes: { "": "defaultRoute" }, defaultRoute: function () { Theater.movies = new Theater.Collections.Movies() new Theater.Views.Movies({ collection: Theater.movies }); Theater.movies.fetch(); } }) var appRouter = new Theater.Router(); Backbone.history.start(); </code></pre> <p>the Collection</p> <pre><code>Theater.Collections.Movies = Backbone.Collection.extend({ model: Theater.Models.Movie, url: "scripts/data/data.json", initialize: function () {} }); </code></pre> <p>View that subscribes to the reset event</p> <pre><code>Theater.Views.Movies = Backbone.View.extend({ initialize: function () { _.bindAll(this, "render", "addOne"); this.collection.bind("reset", this.render); this.collection.bind("add", this.addOne); }, render: function(){ console.log("render") console.log(this.collection.length); }, addOne: function (model) { console.log("addOne") } }) </code></pre> <h3>Reference Site</h3> <p><a href="http://bardevblog.wordpress.com/2012/01/16/understanding-backbone-js-simple-example/">http://bardevblog.wordpress.com/2012/01/16/understanding-backbone-js-simple-example/</a></p>
 

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