我正在尝试使用此处解释的新 ember-data 语法:https ://github.com/emberjs/data/blob/master/TRANSITION.md (从Transaction is Gone: Save Individual Records读取)。
当我点击保存按钮时,我Uncaught TypeError: Cannot call method 'save' of undefined
在控制台中收到错误消息。同样在网络选项卡中,没有对 api 的 POST 请求。
模板
<script type="text/x-handlebars" data-template-name="landcode/new">
Code: {{input value=code}}<br />
Image: {{input value=image}}<br />
<button {{action 'saveLandcode'}}>opslaan</button>
app.js(相关代码)
App.Router.map(function() {
this.resource("landcodes"),
this.resource("landcode", function() {
this.route("new");
});
});
App.LandcodeNewRoute = Ember.Route.extend({
model: function() {
this.store.createRecord('landcode');
},
actions: {
saveLandcode: function(){
this.modelFor('landcode').save(); // does not save
}
}
});
App.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'api'
});
App.Store = DS.Store.extend({
adapter: 'App.ApplicationAdapter'
});
App.Landcode = DS.Model.extend({
code: DS.attr('string'),
image: DS.attr('string')
});