Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>to me this looks like something that should be done mostly by the <code>NotesView</code> with a <code>NotesController</code> that stores the <em>Note selection</em></p> <p>Here is the fiddle: <a href="http://jsfiddle.net/colymba/UMkUL/6/" rel="nofollow">http://jsfiddle.net/colymba/UMkUL/6/</a></p> <p>the <code>NotesController</code> would hold all the notes and a record of the selected one:</p> <pre><code>App.NotesController = Ember.ArrayController.extend({ content: [], selectedNote: null, selectNote: function(id){ var note = this.get('content').findProperty('id', id); this.set('selectedNote', note); } }); </code></pre> <p>with the <code>NotesView</code>observing that selection and showing/hiding elements of the list accordingly</p> <pre><code>App.NotesView = Ember.View.extend({ templateName: 'notes', refresh: function(){ var view = this.$(), selection = this.get('controller.selectedNote'); if (view) { view.find('li').show(); if (selection) view.find('li.note_'+selection.id).hide(); } }.observes('controller.selectedNote') }); </code></pre> <p>Here is the <code>Note</code> object and it's 2 templates (when in a list or displayed in full). The <em>ListView</em> handles the <code>click</code> event and passes the <code>id</code> to the <code>NotesController</code>.</p> <pre><code>App.Note = Ember.Object.extend({ name: '', content: '' }); App.NoteView = Ember.View.extend({ templateName: 'note' }); App.NoteListItemView = Ember.View.extend({ tagName: 'li', templateName: 'noteListItem', classNameBindings: ['noteID'], noteID: function(){ return 'note_' + this._context.id; }.property(), click: function(e){ this.get('controller').selectNote(this._context.id); } }); </code></pre> <p>in the <code>NotesView</code> template everything is displayed and if there is a <code>selectedNote</code>, we display the <code>Note</code> again in full:</p> <pre><code>{{#each note in controller}} {{#with note}} {{view App.NoteListItemView}} {{/with}} {{/each}} {{#if selectedNote}} {{#with selectedNote}} {{view App.NoteView}} {{/with}} {{/if}} </code></pre> <p>the <code>Routes</code> to put it together</p> <pre><code>App.Router.map(function() { this.resource('notes', { path: "/notes" }); }); App.IndexRoute = Ember.Route.extend({ enter: function() { this.transitionTo('notes'); } }); App.NotesRoute = Ember.Route.extend({ model: function() { return [ App.Note.create({id: 1, name: 'Milk', content: '15% fresh milk'}), App.Note.create({id: 2, name: 'Juice', content: 'Orange with pulp'}), App.Note.create({id: 3, name: 'Cereals', content: 'Kelloggs Froot Loops'}), ]; }, setupController: function(controller, model) { controller.set('content', model); }, renderTemplate: function(controller, model) { this.render('notes', { outlet: 'content' }); } }); </code></pre>
    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.
    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