Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I took time to redo your example the way i feel things should be done properly with Emberjs. You should rather make sure of transaction and properly define your views and then all your issues get taken care of. So here's how i think you should do this</p> <ul> <li><p>Define a view for the textfield to capture the value being entered or just bind it to the model property. </p></li> <li><p>Listing items and adding a new item to the list should be done in two different views and should not be mixed together</p></li> </ul> <blockquote> <pre><code>&lt;script type="text/x-handlebars"&gt; {{outlet}} &lt;div&gt; {{outlet 'addItem'}} &lt;/div&gt; &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; {{#each item in controller}} &lt;li&gt; {{#unless item.isNew}} {{item.title}} {{/unless}} &lt;/li&gt; {{/each}} &lt;/ul&gt; &lt;/script&gt; </code></pre> </blockquote> <ul> <li><p>Define different states for listing items and adding a new one</p></li> <li><p>To benefit from automatic binding of your text field value to the model property, you need to associate an <code>ObjectController</code> to the <code>TodoItemsNew</code> route</p></li> <li>Finally, make use of transaction to create and commit records to the store</li> </ul> <blockquote> <pre><code>window.App = Em.Application.create(); App.TodoItem = DS.Model.extend({ title: DS.attr('string') }); App.TodoItem.FIXTURES = [{ id: 1, title: 'Lorem' }, { id: 2, title: 'Ipsum' }]; App.store = DS.Store.create({ 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({ transaction: App.store.transaction(), setupController:function(controller) { console.info(controller.toString()); controller.set('content',this.transaction.createRecord(App.TodoItem)); }, renderTemplate: function() { this.render('addItem',{ into:'application', outlet:'addItem', }) }, events: { addItem: function() { this.transaction.commit(); this.transitionTo('todo_items'); } } }); App.TodoItemsController = Em.ArrayController.extend(); App.TodoItemsNewController = Em.ObjectController.extend(); App.TextField = Ember.TextField.extend({ insertNewline: function () { this.get('controller').send('addItem') } }); </code></pre> </blockquote> <p><a href="http://jsfiddle.net/AaZGw/1/" rel="nofollow">Here</a>' is a working version of the example on jsfiddle. Hopefully, i helped with this example clarify some of your issues.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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