我正在从 Ember 数据 0.13 迁移到 1.0.0 beta。根据文档( https://github.com/emberjs/data/blob/master/TRANSITION.md ),以下内容应该有效:
App.AuthorsNewRoute = Ember.Route.extend({
model: function () {
return this.store.createRecord('author');
},
actions: {
save: function() {
this.modelFor('author').save();
}
}
})
但是,就我而言,我总是收到“无法调用未定义的方法‘保存’错误”。
当使用“this.get('currentModel').save();”时,它在路由中使用保存操作时起作用。将保存操作放入 Controller 时,它不再起作用。相同的错误:无法调用未定义的“保存”方法”错误。
如何访问 Controller 中新创建的记录并保存它?
有人可以提供一个简单的例子吗?
谢谢 马克最佳答案
您有权在 route 使用它:
this.get('currentModel').save();
在 Controller 中您应该使用:
this.get('model').save();
关于ember.js - Ember Data 1.0.0 : this. modelFor ('author' ).save 失败 - 如何在 Controller 中保存新创建的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18561276/