wiradikusuma
wiradikusuma

Reputation: 1909

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.

Upvotes: 5

Views: 4169

Answers (1)

Paul
Paul

Reputation: 18597

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

Upvotes: 9

Related Questions