title: Rendering a collection in Backbone
body: <p>I have a model working which looks something like this</p>
  
  <pre><code>collection=
  {
  foo:[ [1,1], [2,2], [3,3] ] 
  bar: [ [1,1], [2,2], [3,3] ] 
  }
  </code></pre>
  
  <p>I am rendering this out to view in backbone by doing this:</p>
  
  <pre><code>template: JST["backbone/templates/first"]
  collection.each (data) -&gt;
        foo = data.attributes.foo
        bar = data.attributes.bar
        for foos in foo
          view = new Traveltime.Views.ViewExtractTimeList(model: foos)
          $('ul.listcontainer').append(view.render().el)
        for bars in bar
          console.log perce
          view = new Traveltime.Views.ViewExtractPercentList(model: bars)
          $('ul.2ndlistcontainer').append(view.render().el)
  </code></pre>
  
  <p>Template first:</p>
  
  <pre><code>&lt;ul class="listcontainer"&gt;
  &lt;/ul&gt;
  
  &lt;ul class="2ndlistcontainer"&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I then have 2 more views which handle a seperate tempate each:</p>
  
  <pre><code>class App.Views.ViewExtractFoo extends Backbone.View
  
    tagName: "li"
    template: JST['backbone/templates/foo']
  
    render: -&gt;
      $(@el).html(@template(content: @model))
      this
  
  
  class App.Views.ViewExtractBar extends Backbone.View
  
    tagName: "li"
    template: JST['backbone/templates/bar']
  
    render: -&gt;
      $(@el).html(@template(content: @model))
      this
  </code></pre>
  
  <p>template looks like this (swap foo for bar for bar example):</p>
  
  <pre><code>&lt;li&gt;
  Foo: &lt;%=content.attributes.foo%&gt;
  &lt;/li&gt;   
  </code></pre>
  
  <p>Now this works, and it works well. But it feels REALLY messy. I am using backbone in rails so have like 6 or more different files just take a JSON request and rendering it. It feels nasty and there is a better way. I am just not sure which one it is yet.</p>
  
  <p>I am just thinking if I did this in Rails i could have one view that could pull this all out!? </p>
  
  <p>Can i use collection.each and somehow pass the nested collection to the template? </p>
  
  <p>Bit stuck here, and I am by no means good at this so any help is greatly received.</p>