emberjs new-router-V3/controller无法使用ember-data创建或编辑记录

brg*_*brg 2 ember.js ember-data ember-router

在这个jsfiddle中,我有EmBlog.PostsNewRouteEmBlog.PostsEditRoute.路由包含"保存,取消和销毁"的事件.

当我创建一个新记录时,它只在内存中创建并且从不调用store.commit(),并且在控制台中,它会抛出错误:

未捕获的TypeError:无法调用未定义的方法'commit'

当我尝试编辑时,它会抛出相同的错误,但编辑仍然只在内存中发生.

销毁行动也失败了.

当我打电话取消时,我得到:

无法读取undefined的属性'defaultTransaction'

大多数代码都在jsfiddle中.保存和取消事件遵循耶胡达描述的模式:

    App.NewUserRoute = Ember.Route.extend({
      model: function() {
         return App.User.createRecord();
      },

     events: {
         save: function(user) {
          this.get('store').commit();
         }
     }
   });
Run Code Online (Sandbox Code Playgroud)

谢谢

Mik*_*tti 5

更新小提琴!它现在正在创建,编辑和销毁用例.有关我更改内容的详细信息,请参见下文

当我创建一个新记录时,它只在内存中创建它并且从不调用store.commit()并在控制台中抛出错误:Uncaught TypeError:无法调用undefined方法'commit'

原始PostNewRoute失败,因为this.store未定义.也this.content可能是未定义的.

save: function(post) {
  this.store.commit();
  this.content.addObserver('id', this, 'afterSave');
 },
Run Code Online (Sandbox Code Playgroud)

更新版本调用提交帖子的事务.还会在创建记录后使用post.one回调进行转换.

 save: function(post) {
   post.one('didCreate', this, function(){
     this.transitionTo('posts.show', post);
   });
   post.get('transaction').commit();
 },
Run Code Online (Sandbox Code Playgroud)

稍后将更新其他更新的详细信息......

当我尝试编辑时,它会抛出相同的错误,但编辑仍然只在内存中发生.

销毁行动也失败了.

当我调用cancel时,我得到:无法读取undefined的属性'defaultTransaction'