Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>2014/02/18 — updated to accommodate the improvements noted by @vaughan and @Thom-Nichols in the comments</p> <hr> <p>In many of my itemView/layouts I do this:</p> <pre><code>var Layout = Backbone.Marionette.Layout.extend({ ... onRender: function () { // Get rid of that pesky wrapping-div. // Assumes 1 child element present in template. this.$el = this.$el.children(); // Unwrap the element to prevent infinitely // nesting elements during re-render. this.$el.unwrap(); this.setElement(this.$el); } ... }); </code></pre> <p>The above code only works when the wrapper div contains a single element, which is how I design my templates. </p> <p>In your case <code>.children()</code> will return <code>&lt;tr class="angry_cat"&gt;</code>, so this should work perfect.</p> <p>I agree, it does keep the templates much cleaner.</p> <p>One thing to note: </p> <p>This technique does not force only 1 child element. It blindly grabs <code>.children()</code> so if you've incorrectly built the template to return more than one element, like the first template example with 3 <code>&lt;td&gt;</code> elements, it won't work well. </p> <p>It requires your template to return a single element, as you have in the second template with the root <code>&lt;tr&gt;</code> element.</p> <p>Of course it could be written to test for this if need be.</p> <hr> <p><a href="http://codepen.io/somethingkindawierd/pen/txnpE">Here is a working example for the curious: http://codepen.io/somethingkindawierd/pen/txnpE</a></p>
    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. 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.
 

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