Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I should have posted my solution a while back - there might well be a better way, but this is the convention I've gone with:</p> <p>All of the following code is in the <strong>card view</strong> (which is where the notes are displayed). </p> <p>First, I bind a <code>renderNotes</code> method to the <code>'reset'</code> event on the card's notes collection:</p> <pre><code>initialize: function () { _.bindAll(this); this.model.get('notes').on('reset', this.renderNotes); var self = this; this.model.get('notes').on('add', function(addedNote, relatedCollection) { self.renderNote(addedNote); }); } </code></pre> <p>I also bind to the <code>'add'</code> on that collection to call a singular <code>renderNote</code>. </p> <p>The renderNotes and renderNote methods work like this:</p> <pre><code>renderNotes: function () { if (this.model.get('notes')) { this.model.get('notes').each(this.renderNote); } }, renderNote: function (note) { var noteView = new Workflow.Views.Note({ model: note }); this.$('.notes').append(noteView.render().el); }, </code></pre> <p>Then, the last piece of the puzzle is to actually hit the server up for the card's notes (which will in turn fire the <code>'reset'</code> event I bound to above). I do this in the card view's <code>render</code> method:</p> <pre><code>render: function () { // render all of the eager-loaded things this.model.get('notes').fetch(); return this; }, </code></pre> <p>As @user1248256 kindly helped me work out in the comments on my OP, the confusion was mainly in that I expected <code>fetchRelated</code> to pull down lazy-loaded records - that's actually not the case.</p> <p>As a side-note, this view is actually a modal and be opened and closed (removed from the page). To prevent the zombie events problem described in <a href="http://www.google.com.au/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=1&amp;ved=0CFEQFjAA&amp;url=http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/&amp;ei=Up8EULXmBe7omAXmm_2kBg&amp;usg=AFQjCNEP8_EpNm9a5ygpvsRfviq-izWdIA&amp;sig2=xXQ3eYohyrSSZ0rrhYz8jQ" rel="nofollow">this excellent post</a>, I also manually unbind the events mentioned above.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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