Note that there are some explanatory texts on larger screens.

plurals
  1. POOld Backbone View Causing extra Event Triggers
    text
    copied!<p>OK, I've done some reading on this and I'm pretty sure I know what the problem relates to I Just don't know the best way to fix it. I've got the standard backbone router that sets me up with an item details view, then when I click on a button called "start" it creates a new view which takes me to a sort of a game that people can play with some buttons on the bottom that have "click" events attached. This second view is not called through the router but directly from the first view. </p> <p>The problem is the second time someones goes back to the homescreen and does it again, this time there are two events attached to each button. The third time there are three events. Obviously the original views are still listening to these buttons. I've read about this and calling the Remove() method but is this what I need to do? If so where do I call remove? Relevant Code below:</p> <p>1ST VIEW</p> <pre><code>window.GameDrillView = Backbone.View.extend({ initialize: function () { this.render(); }, render: function () { $(this.el).html(this.template(this.model.toJSON())); return this; }, events: { "click .start" : "startGameDrill", }, startGameDrill: function () { var start = $('#start').val();. var stop = $('#stop').val();. var StartView = new GameDrillStartView({model: this.model, el: $('#content')[0], start: start, stop:stop}); } </code></pre> <p>});</p> <p>START VIEW</p> <pre><code>window.GameDrillStartView = Backbone.View.extend({ // declare variables initialize: function () { this.render(); }, events: { "click .nextstage" : "nextstage", // 2ND TIME THROUGH GETS CALLED TWICE }, nextstage: function () { // Do some stuff // this.render(); //Re-render }, render: function () { // Do some variables stuff this.$el.html(this.template(jQuery.extend(this.model.toJSON(), extended_options)));.. return this; } }); </code></pre>
 

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