Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js - Temporarily disabling (events in) View

TL;DR How to temporarily disable a View so I can safely load another View, then safely close the loaded View to return to the original View?

I have the following scenario:

  1. User opens /search which loads SearchView.
  2. User clicks a button to perform search.
  3. Collection inside SearchView is filled with data, UI is updated to reflect that.
  4. User clicks a result item.
  5. SearchView is disabled (only need to disable events?).
  6. ItemView is loaded, displaying the item detail.
  7. User clicks a button to close ItemView.
  8. SearchView is re-enabled.

What is the best way to achieve point 5 and 8? I'm thinking of calling SearchView.unbind() (for point 5) and SearchView.bind() (for point 8).

Bonus: It would be better if the solution is stack-like. I.e. View A loads View B which can load View C. When View C is closed, View B is reinstated, etc.

like image 366
wiradikusuma Avatar asked Mar 15 '12 17:03

wiradikusuma


1 Answers

Try calling SearchView.undelegateEvents() for point 5, and then SearchView.delegateEvents() for point 8.

like image 112
Paul Avatar answered Nov 03 '22 05:11

Paul