在此jsfiddle ,我有 EmBlog.PostsNewRoute 和 EmBlog.PostsEditRoute。这些路线包含“保存、取消和销毁”事件。
当我创建一条新记录时,它只在内存中创建它,而不会调用 store.commit() ,并且在控制台中,它会抛出错误:
未捕获类型错误:无法调用未定义的“commit”方法
当我尝试编辑时,它会抛出相同的错误,但编辑仍然只发生在内存中。
销毁操作也失败。
当我调用取消时,我得到:
无法读取未定义的属性“defaultTransaction”
大部分代码都在jsfiddle中。保存和取消事件遵循 Yehuda here 描述的模式。 :
App.NewUserRoute = Ember.Route.extend({
model: function() {
return App.User.createRecord();
},
events: {
save: function(user) {
this.get('store').commit();
}
}
});
谢谢
最佳答案
已更新fiddle !它现在用于创建、编辑和销毁用例。有关我更改的详细信息,请参阅下文...
When I create a new record, it only creates it in memory and never calls the store.commit() and in the console, it throws the error: Uncaught TypeError: Cannot call method 'commit' of undefined
原来的PostNewRoute
失败,因为this.store未定义。而且 this.content
也将是未定义的。
save: function(post) {
this.store.commit();
this.content.addObserver('id', this, 'afterSave');
},
更新后的版本调用帖子事务的提交。还使用 post.one 回调在创建记录后进行转换。
save: function(post) {
post.one('didCreate', this, function(){
this.transitionTo('posts.show', post);
});
post.get('transaction').commit();
},
稍后将更新其他更新的详细信息...
When I try to edit, it throws thesame error but then the edit still happens only in memory.
The destroy action also fails.
When I call cancel, I get: Cannot read property 'defaultTransaction' of undefined
关于ember.js - emberjs new-router-V3/controller 无法使用 ember-data 创建或编辑记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14431010/