Skip to content Skip to sidebar Skip to footer

Saving User Data More Than Once

I started learning Backbone JS, I just had some doubt. Iam creating this with my below code I mean this user form http://backbonetutorials.com/videos/beginner/#/new Scenario 1 Upd

Solution 1:

Lol. I just answered this question yesterday. Looks like someone has to alert the author of his tutorial that he's creating Zombie Views!

To answer you question, the reason the first scenario works is because you create only one view and then use your router to render that same view. But if you'll look at Scenario 2 there every subsequent time you follow the route #new you create another AddUserView view and you're rendering that view. All your past views do not go away because they are still listening to events in some element of the DOM they manage. In your case, you have

events: {
  'submit .add-user-form': 'saveOrUpdateUser' 
}

so each rendered view is listening to the <submit> button element.

Check out this answer, Backbone js Model Save more than once, for more details. And of course, don't miss Derick Bailey's classic article Zombies! RUN! (Managing Page Transitions In Backbone Apps). (BTW, using Derick's Marionette, a very active, stable and well supported Backbone Framework you'll have plenty of tools at your disposal to help you avoid zombie views).


Post a Comment for "Saving User Data More Than Once"