我正在使用Ember Data 1.0.0-beta1和EmberJS 1.0.0。
我的保存操作
App.UsersNewController = Ember.ObjectController.extend({
actions: {
save: function() {
var self = this;
self.content.save().then(function() {
self.transitionToRoute('index');
});
},
cancel: function() {
this.content.deleteRecord();
this.transitionToRoute('index');
}
}
});
调用,它会抛出一个Uncaught TypeError
Uncaught TypeError: Cannot call method 'lookup' of undefined ember-data.js?body=1:6576
DS.RESTAdapter.DS.Adapter.extend.serializerFor ember-data.js?body=1:6576
DS.RESTAdapter.DS.Adapter.extend.createRecord ember-data.js?body=1:6492
_commit ember-data.js?body=1:2490
(anonymous function) ember-data.js?body=1:1991
Ember.EnumerableUtils.forEach ember.js?body=1:1786
DS.Store.Ember.Object.extend.flushPendingSave ember-data.js?body=1:1978
DeferredActionQueues.flush ember.js?body=1:5463
Backburner.end ember.js?body=1:5547
Backburner.run ember.js?body=1:5586
Ember.run ember.js?body=1:5917
ActionHelper.registeredActions.(anonymous function).handler ember.js?body=1:32781
(anonymous function) ember.js?body=1:19003
Ember.handleErrors ember.js?body=1:557
(anonymous function) ember.js?body=1:18995
jQuery.event.dispatch jquery.js?body=1:5096
elemData.handle
编辑:这是路线
App.UsersNewRoute = Ember.Route.extend({
model: function() {
return this.store.createRecord('user');
},
setupController: function(controller, model) {
controller.set('content', model);
}
});
型号:
App.User = DS.Model.extend({
email: DS.attr('string'),
password: DS.attr('string'),
passwordConfirmation: DS.attr('string')
});
商店:
App.Store = DS.Store.extend
revision: 13
adapter: DS.RESTAdapter.create()
答案 0 :(得分:0)
似乎您的RESTAdapter没有对容器的引用。通常在ember创建适配器时设置 - 由于您手动创建实例,因此可能会丢失。尝试将App.Store声明更改为仅使用默认值:
App.Store = DS.Store.extend({})