Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thank you Ken for answering my question. It indeed feels like a more proper of way of doing this in Ember. However, I still think it's difficult to get the hang of which objects are accessible from where...</p> <p>Your example inspired me to do a rewrite of my code. I also made some changes to your approach:</p> <ul> <li>I'm not sure if it's the best practice, my I don't create a <code>store</code> instance. Instead I define a <code>Store</code> class. </li> <li>The content for the <strong>TodoItemsNewController</strong> is set by calling the model property on the corresponding route.</li> <li><p>renderTemplate in the TodoItemsNewRoute only needs the outlet key.</p> <pre><code>&lt;script type="text/x-handlebars"&gt; {{outlet}} &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="todo_items"&gt; {{#linkTo 'todo_items.new'}}Add Todo Item{{/linkTo}} &lt;ul&gt; {{outlet "addItem"}} {{#each controller}} &lt;li&gt; {{#unless isNew}} {{title}} {{/unless}} &lt;/li&gt; {{/each}} &lt;/ul&gt; &lt;/script&gt; &lt;script type="text/x-handlebars" data-template-name="todo_items/new"&gt; {{view Ember.TextField valueBinding="title" placeholder="Enter title"}} </code></pre> <h2> </h2> <pre><code>window.App = Em.Application.create(); App.TodoItem = DS.Model.extend({ title: DS.attr('string', { defaultValue: "unknown" }) }); App.TodoItem.FIXTURES = [{ id: 1, title: 'Lorem' }, { id: 2, title: 'Ipsum' }]; App.Store = DS.Store.extend({ revision: 11, adapter: DS.FixtureAdapter.create() }); App.Router.map(function() { this.resource('todo_items', function() { this.route('new'); }); }); App.IndexRoute = Em.Route.extend({ redirect: function() { this.transitionTo('todo_items'); } }); App.TodoItemsRoute = Em.Route.extend({ model: function() { return App.TodoItem.find(); } }); App.TodoItemsNewRoute = Em.Route.extend({ model: function() { return App.TodoItem.createRecord(); }, renderTemplate: function() { this.render({ outlet: 'addItem' }); } }); App.TodoItemsNewView = Em.View.extend({ tagName: 'li' }); </code></pre></li> </ul> <p>The updated example is on <a href="http://jsfiddle.net/bazzel/BkFYd/" rel="nofollow">jsFiddle</a>.</p> <p>Any reviews are welcome.</p>
 

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