[Answer]-Collection is empty when a route calls it, but if I go away and come back, the collection holds what it is supposed to

1👍

It looks like your listening to the wrong collection event. Try using

window.NoteListView = Backbone.View.extend({
    // ...
    initialize: function () {
        this.collection.bind('reset', this.render);
    }
    // ...
});
window.NotesRouter = Backbone.Router.extend({
    // ...
    initialize: function() {
        notes.fetch({reset: true});
    }
    // ...
});

Right now you are firing off an async collection.fetch(), which will eventually load the data. Problem is, once that data is loaded into the collection, it won’t fire a change event, just a bunch of adds. When you go to the blank page and back, you’re data has arrived by the second render call and displays properly.

If you modify your fetch() to throw a reset event and then listen for that, you’ll have a freshly rendered NoteList once the data comes in without the need to go to the blank page.

Leave a comment