Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From what you're saying, it sounds like you really only want a single collection instance, which will hold the items that you're referring to (model instances in the collection).</p> <p>There should also be 3 views in this scenario — one for the <code>List</code> (the left panel), one for the individual <code>ListItem</code>s in that list and one for displaying information about the <code>Item</code> itself (the right panel).</p> <h2>List</h2> <p>The <code>List</code> view holds a reference to the collection and appends a <code>ListItem</code> view for each item in the collection. You may later want to subscribe to events on the collection to automatically append/remove items from the list when new ones are added/remove from the collection. This is the view where that should be handled.</p> <pre><code>List = Backbone.View.extend({ el: '#list', initialize: function(){ _.bindAll(this) this.collection.each(this.appendItem) }, appendItem: function(item) { view = new ListItem({model: item}) $(this.el).append(view.render().el) } }) </code></pre> <h2>ListItem</h2> <p>The <code>ListItem</code> view holds a reference to a particular model and renders the list item inside the list for that model. It also handles the click event, which renders the <code>Item</code> view for that model.</p> <pre><code>ListItem = Backbone.View.extend({ tagName: 'li', events: { "click" : "showInfo" }, initialize: function(){ _.bindAll(this) }, render: function(){ $(this.el).html(renderTemplate("listItem", this.model)) return this }, showInfo: function(){ view = new Item({model: this.model}) $('#item').html(view.render().el) } }) </code></pre> <h2>Item</h2> <p>The <code>Item</code> view also holds reference to a particular model and renders information about that model. This is the right panel that you're referring to.</p> <pre><code>Item = Backbone.View.extend({ initialize: function(){ _.bindAll(this) }, render: function(){ $(this.el).html(renderTemplate("item", this.model)) return this } }) </code></pre> <p><a href="http://jsfiddle.net/XRGFe/" rel="nofollow">Here is a fiddle</a> to show things in action.</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. 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