Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use the the official Ember Guides for help: <a href="http://emberjs.com/guides/" rel="nofollow">http://emberjs.com/guides/</a>. The example there is with a simple application with many posts (in your case projects) and each post has many comments (in your case notes). The only thing missing is the option to toggle a note, instead of open it permanently. </p> <p>Using the Guide only, your router should look something like this:</p> <pre><code>App.Router.map(function () { this.resource('project', { path: '/project/:project_id' }, function () { this.resource('note', { path: '/note/:note_id' }, function () {}); }); }); App.ProjectController = Ember.ObjectController.extend({ toggle: function(note) { var isOpen = !note.get('isOpen'); if (isOpen) { this.transitionTo('note', note); } else { this.transitionTo('project', this.get('content')); } this.get('notes').forEach(function(note) { note.set('isOpen', false); }); note.set('isOpen', isOpen); } }); </code></pre> <p>Then, your project template should list all the notes and provide a place to open a note and view it:</p> <pre><code>&lt;script type="text/x-handlebars" data-template-name="project"&gt; {{#each note in notes}} &lt;li&gt; &lt;button type="button" {{action toggle note}}&gt; {{note.name}} &lt;/button&gt; &lt;/li&gt; {{/each}} {{outlet}} &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="note"&gt; {{description}} &lt;/script&gt; </code></pre> <p>To clarify things: ProjectController is an ObjectController with a content set to the currently opened project. ProjectController#notes is where all the notes for the currently loaded project will be. The project/note.handlebars will simply describe the note, as you desire it to be shown inside the project page.</p> <p>Here is a working fiddle (with some boilerplate code added): <a href="http://jsfiddle.net/ZcspT/6/" rel="nofollow">http://jsfiddle.net/ZcspT/6/</a></p> <p>EDIT:</p> <p>Here is the version without routes (only the different parts):</p> <pre><code>App.Router.map(function () { this.resource('project', { path: '/project/:project_id' }); }); App.NoteView = Ember.View.extend({ templateName: 'note', content: null, classNameBindings: ['content.isOpen::hidden'] }); App.ProjectController = Ember.ObjectController.extend({ toggle: function(note) { var isOpen = !note.get('isOpen'); this.get('notes').forEach(function(note) { note.set('isOpen', false); }); note.set('isOpen', isOpen); } }); </code></pre> <p>The templates:</p> <pre><code>&lt;script type="text/x-handlebars" data-template-name="project"&gt; {{#each note in notes}} &lt;li&gt; &lt;a {{action toggle note}} href="#"&gt;{{note.name}}&lt;/a&gt; &lt;/li&gt; {{/each}} &lt;div id="noteSection"&gt; {{#each note in notes}} {{view App.NoteView contentBinding="note"}} {{/each}} &lt;/div&gt; &lt;/script&gt; </code></pre> <p>The stylesheet:</p> <pre><code>.hidden { display: none; } </code></pre> <p>Example: <a href="http://jsfiddle.net/ZfWhc/1/" rel="nofollow">http://jsfiddle.net/ZfWhc/1/</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.
 

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