0

I am creating a web app using backbone.js in which there are multiple views which are rendering fine. The main problem is handling the back button event. When i press a back button the earler view renders properly but by following the same process of calling the fetch(). I dont want the call the fetch() instead render the view with the earlier data received.

Is there any way to do it?

Jitu
  • 284
  • 1
  • 3
  • 15

1 Answers1

3

You essentially want to have a condition on the fetch. There are a couple of approaches, one would be to assign it to the instance like this:

myAction: function() {
    if (!this.collection) {
        this.collection = new MyCollection();
        this.collection.fetch()
    }
    view = new View({collection: this.collection});
    // ... render ...
}
Tanzeeb Khalili
  • 7,324
  • 2
  • 23
  • 27