gpt4 book ai didi

ember.js - Ember Data 1.0.0 : this. modelFor ('author' ).save fails - 如何在 Controller 中保存新创建的记录?

转载 作者:行者123 更新时间:2023-12-02 05:57:58 24 4
gpt4 key购买 nike

我正在从 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('模型').save();

关于ember.js - Ember Data 1.0.0 : this. modelFor ('author' ).save fails - 如何在 Controller 中保存新创建的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18561276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com