Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You just need to pass in your model attributes as an object into the underscore template function. The first argument is the template, the second - your data. You can pass in any object data but underscore plays real nice with model.toJSON() for obvious reasons.</p> <pre><code>this.$('#insertWherever').html(_.template($('#busList'), stopModel.toJSON())); </code></pre> <p>And your template would look something like this.</p> <pre><code>&lt;script id="busList" type="text/html"&gt; &lt;ul&gt; &lt;% _.each(listabus, function(busNumber){ %&gt; &lt;li&gt;&lt;%= busNumber %&gt;&lt;/li&gt; &lt;% }); %&gt; &lt;/ul&gt; &lt;/script&gt; </code></pre> <p>To summarize, the <code>&lt;% %&gt;</code> is a way to escape and run arbitrary JS code. The <code>&lt;%= %&gt;</code> is a way to interpolate or output stuff into your template.</p> <p>See <a href="http://underscorejs.org/#template" rel="nofollow">http://underscorejs.org/#template</a> and <a href="http://underscorejs.org/#each" rel="nofollow">http://underscorejs.org/#each</a></p> <p>If you're using require.js, you can download a plugin called text!</p> <p>This allows you to define HTML files in your dependencies and have your templates reside in their own individual files. This is opposed to the above method which uses an embedded script tag and jquery to grab the template from within whatever view you're working with.</p> <p>See plugins / text @ <a href="http://requirejs.org/docs/download.html" rel="nofollow">http://requirejs.org/docs/download.html</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. This table or related slice is empty.
    1. 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