Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Good question! I think the best solution would be to implement an </p> <blockquote> <p><strong>EventBus</strong> aka <strong>EventDispatcher</strong></p> </blockquote> <p>to coordinate all events among the different areas of your application.</p> <p>Going that route seems clean, loosely coupled, easy to implement, extendable and it is actually suggested by the backbone documentation, see <a href="http://documentcloud.github.com/backbone/#Events-on" rel="nofollow noreferrer">Backbone Docs</a></p> <p>Please also read more on the topic <a href="http://thurloat.com/2012/01/21/backbonejs-readable-modular-testable-views" rel="nofollow noreferrer">here</a> and <a href="https://stackoverflow.com/a/7534376/358114">here</a> because (even though I tried hard) my own explanation seems kind of mediocre to me. </p> <p>Five step explanation:</p> <ol> <li><p>Create an EventBus in your main or somewhere else as a util and include/require it</p> <blockquote> <pre><code> var dispatcher = _.clone(Backbone.Events); // or _.extends </code></pre> </blockquote></li> <li><p>Add one or more callback hanlder(s) to it</p> <blockquote> <pre><code> dispatcher.CELL_CLICK = 'cellClicked' </code></pre> </blockquote></li> <li><p>Add a trigger to the Eventlistener of your childView (here: the CellView)</p> <blockquote> <pre><code> dispatcher.trigger(dispatcher.CELL_CLICK , this.model); </code></pre> </blockquote></li> <li><p>Add a Listener to the Initialize function of your parentView (here: the BoardView)</p> <blockquote> <pre><code> eventBus.on(eventBus.CARD_CLICK, this.cardClick); </code></pre> </blockquote></li> <li><p>Define the corresponding Callback within of your parentView (and add it to your _.bindAll)</p> <blockquote> <pre><code> cellClicked: function(model) { // do what you want with your data here console.log(model.get('someFnOrAttribute') } </code></pre> </blockquote></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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