Note that there are some explanatory texts on larger screens.

plurals
  1. POSame Ember.JS template for display/edit and creation
    primarykey
    data
    text
    <p>I am writing a CRUD application using Ember.JS:</p> <ul> <li>A list of “actions” is displayed;</li> <li>The user can click on one action to display it, or click on a button to create a new action.</li> </ul> <p>I would like to use the same template for displaying/editing an existing model object and creating a new one.</p> <p>Here is the router code I use.</p> <pre><code>App = Ember.Application.create(); App.Router.map(function() { this.resource('actions', {path: "/actions"}, function() { this.resource('action', {path: '/:action_id'}); this.route('new', {path: "/new"}); }); }); App.IndexRoute = Ember.Route.extend({ redirect: function() { this.transitionTo('actions'); } }); App.ActionsIndexRoute = Ember.Route.extend({ model: function () { return App.Action.find(); } }); App.ActionRoute = Ember.Route.extend({ events: { submitSave: function () { this.get("store").commit(); } } }); App.ActionsNewRoute = Ember.Route.extend({ renderTemplate: function () { this.render('action'); }, model: function() { var action = this.get('store').createRecord(App.Action); return action; }, events: { submitSave: function () { this.get("store").commit(); } } }); </code></pre> <p>The problem is that when I first display an action, and then come back to create a new one, it looks like the template is not using the newly created record, but use instead the one displayed previously.</p> <p>My interpretation is that the controller and the template are not in sync. How would you do that? Maybe there is a simpler way to achieve this?</p> <p>Here is a JSBin with the code: <a href="http://jsbin.com/owiwak/10/edit" rel="nofollow">http://jsbin.com/owiwak/10/edit</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. 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