【发布时间】:2013-11-08 02:33:25
【问题描述】:
我正在尝试使用新的 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')
});
【问题讨论】:
标签: ember.js ember-data