安装在服务器上之后,Ember更新ID

我有一个应用程序,将博客文章保存到服务器,服务器为其分配一个id 。 然后,应用程序被路由到post,但我不知道如何成功保存后更新id

我玩过模型上的didCreate事件,但我似乎无法得到任何工作。

 // create controller App.PostsCreateController = Ember.ObjectController.extend({ actions: { save: function() { // just before saving, we set the creationDate this.get('model').set('creationDate', new Date()); // create a record and save it to the store var newPost = this.store.createRecord('post', this.get('model')); newPost.save(); // redirects to post itself this.transitionToRoute('post', newPost); } } }); // model App.Post = DS.Model.extend({ title: DS.attr(), post_content: DS.attr(), tags: DS.attr(), creationDate: DS.attr() }); 

什么是从服务器获得id的正确方法? 这是一个节点服务器,如果这有所作为。

你的服务器只需要返回id和保存的数据,模型将被更新,以使用该id。 在你的情况下,这样的事情:

 { post: { id: 1, title: 'Rails is omakase', post_content: 'Loremipsum...' } }